将ng-model绑定到ng-repeat不起作用
Binding ng-model to ng-repeat not working
我试图将ng-model与ng-repeat动态绑定,但它似乎不起作用。输入。占位符和输入。fa都按预期工作,但我似乎无法将ng-model绑定到任何东西,因为它给了我一个错误。
相关的HTML
<li class="animate-repeat" ng-repeat="input in accountInfo">
<div class="input-group input-group-icon">
<input type="text" placeholder="{{input.placeholder}}" ng-model="{{input.model}}"/>
<div class="input-icon"><i class="fa {{input.fa}}"></i></div>
</div>
</li>
我的accountInfo对象数组。
$scope.accountInfo = [
{
model: 'user.fullName',
placeholder: 'Full Name',
fa: 'fa-user',
},
{
model: 'user.email',
placeholder: 'Email Address',
fa: 'fa-envelope',
},
{
model: 'user.password',
placeholder: 'Password',
fa: 'fa-key',
},
{
model: 'user.phone',
placeholder: 'Phone Number',
fa: 'fa-phone',
},
];
我得到的错误
错误链接请帮
ng-model
未被插值;你不应该用{{
包裹它。
<input ... ng-model="input.model">
应该可以正常工作。
编辑:对不起,我没有看到你试图动态设置ng模型——我的道歉。
最简单的解决方案是使用accountInfo
中的引用,如果user
在该作用域中可用:
$scope.accountInfo = [{
model: user.fullName,
placeholder: 'Full Name',
...
否则,您可以在$scope
上声明一个对象,并手动将其链接到模型:
// ... some place without access to `user`
$scope.accountInfo = [{
model: 'fullName',
placeholder: 'Full Name',
...
// some place with access to `user`
$scope.inputs = {
fullName: user.fullName,
email: user.email,
...
};
// html
<input ... ng-model="inputs[input.model]">
因为ng-model只接受一个引用,所以你所能做的就是对它进行修改。
相关文章:
- 角度无线电按钮ng模型不起作用
- 角度Js ng-disabled不起作用
- 为什么ng节目不起作用
- 带有粘性标题的角度ng视图不起作用
- select中布尔值的Angularjs ng值不起作用
- AngularJS触发ng更改不起作用
- Angular js-ng选项不起作用
- 实时 Angular js ng-hide 不起作用
- 当输入字段位于 ng 重复中时,ng 禁用不起作用
- AngularJS ng重复不起作用
- AngularJS:ng-repeat不起作用
- 尝试输出多维数组时,AngularJS中的ng repeat不起作用
- 在Angularjs应用程序中,使用嵌套对象属性过滤ng repeat不起作用
- AngularJS中不同的过滤器方法"ng-repeat"不起作用
- Angular JS - Binding view和app.js - ng-repeat不起作用
- 将ng-model绑定到ng-repeat不起作用
- ng init与ng repeat不起作用
- Ng-repeat不起作用AngularJs
- Angular js ng-repeat不起作用
- 为什么ng-repeat不起作用