How to auto populate text field in angular js base

2019-08-31 04:58发布

问题:

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.