[英]Populate array into form fields (AngularJS)
I'm new to AngularJS so this might seem silly but I really can't figure it out 我是AngularJS的新手,所以这似乎很愚蠢,但我真的不知道
I've a list of arrays that returns from calling a searchAll
我有一个从调用
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"
需要使用
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 理想情况下,它应该进入输入字段
Any suggestion appreciated! 任何建议表示赞赏!
<!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>
I think, you just want to populate the given object.please refer above code. 我认为,您只想填充给定的对象。请参考上面的代码。 i have added a
<pre>
to see the live object. 我添加了
<pre>
来查看活动对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.