I'm new to AngularJS so this might seem silly but I really can't figure it out
I've a list of arrays that returns from calling a searchAll
console
0: {mobile: "12345678", lastname: "last01", firstname: "first01"}
1: {mobile: "87654321", lastname: "last02", firstname: "first02"}
...
It needs to be populated in separate input fields using ng-repeat="client in ctrl.clients"
<input ... ng-model="ctrl.client.firstname"
<input ... ng-model="ctrl.client.lastname"
<input ... ng-model="ctrl.client.mobile"
It'll show up as text if I populate the below
<li>First name: {{client.firstname}}</li>
<li>Last name: {{client.lastname}}</li>
<li>Mobile: {{client.mobile}}</li>
Ideally, it should go into the input fields
中检索innerHTML值任何建议都表示赞赏!
答案 0 :(得分:0)
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body ng-app="myApp">
<div ng-controller="myCtrl as ctrl">
<div ng-repeat="client in ctrl.clients">
<input type="text" ng-model="client.firstname" />
<input type="text" ng-model="client.lastname" />
<input type="text" ng-model="client.mobile" />
</div>
<pre>{{ctrl.clients | json}}<pre>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function() {
this.clients = [{
mobile: "12345678",
lastname: "last01",
firstname: "first01"
}, {
mobile: "87654321",
lastname: "last02",
firstname: "first02"
}];
});
</script>
</body>
</html>
我想,你只想填充给定的对象。请参考上面的代码。我添加了<pre>
来查看实时对象。