How to auto populate text field in angular js based on other form fields

对着背影说爱祢 提交于 2019-12-25 03:24:28

问题


I'm giving an student scenario as example. Assume I have the below scope variables that needs to populated when I select a id.

$scope.student.name;
$scope.student.address;
$scope.student.city;
$scope.student.zip;

The sample html below.

<input type="text" ng-model="student.id"/>
<input type="text" ng-model="student.name"/>
<input type="text" ng-model="student.city"/>
<input type="text" ng-model="student.address"/>
<input type="text" ng-model="student.zip">

In a regular jQuery, I would write on change and trigger. But how do I achieve this in angular way.

I might want to have the entire db values in a hashmap of <studentid,List<studentdetails>> and use this hashmap values to be populated on the respective fields.


回答1:


I know this is probably a little late on the draw to answering this question, but I was searching for an answer to auto-population with Angular today and found that you could populate an input using ng-value and passing it into your value held inside of {{}}.

It would look something like this: ng-value="{{exampleValue}}

Hope this helps.



来源:https://stackoverflow.com/questions/25648307/how-to-auto-populate-text-field-in-angular-js-based-on-other-form-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!