我有包含字符串数组的属性字段:
在 Controller 中我有:
$scope.data = {};
$scope.fields = [
"new0.name",
"new0.type",
"new0.address",
"new0.city",
"new0.postalCode"
];
我认为:
<div class="control-group" ng-repeat="f in fields">
<label class="control-label">Some field name</label>
<div class="controls">
<input type="text" name="{{f}}" ng-model="data.f" class="input-xlarge">
</div>
</div>
在 ng-repeat 中,如何将 f 的值连接到 ng-model
以获得,例如 ng-model ="data.new0.name"?
最佳答案
要使用变量引用对象的属性,请使用括号表示法
data[f]
关于javascript - 在angularjs中动态创建ng-model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20125466/