Angularjs 绑定控制器中的ng重复和ng模型
这是我在这里的第一篇帖子,所以请容忍我,我对AngularJS也是相当陌生的。我正试图用ng repeat创建一个表单,但我的头在棱角的东西周围有困难 控制器中的JS:Angularjs 绑定控制器中的ng重复和ng模型,angularjs,ng-repeat,Angularjs,Ng Repeat,这是我在这里的第一篇帖子,所以请容忍我,我对AngularJS也是相当陌生的。我正试图用ng repeat创建一个表单,但我的头在棱角的东西周围有困难 控制器中的JS: $scope.myCurrentAssets = { cash_equiv: {name: 'Cash & Equivalents', value: 0, tbi: 41}, invest: {name: 'Short Term Investments', value: 0, tbi: 4
$scope.myCurrentAssets = {
cash_equiv: {name: 'Cash & Equivalents', value: 0, tbi: 41},
invest: {name: 'Short Term Investments', value: 0, tbi: 42},
notes_rec: {name: 'Notes Receivable', value: 0, tbi: 43},
account_rec: {name: 'Accounts Receivable', value: 0, tbi: 44},
inventory: {name: 'Inventory', value: 0, tbi: 45},
prepaid: {name: 'Prepaid Expenses', value: 0, tbi: 46},
other: {name: 'Other Current Assets', value: 0, tbi: 47}
};
HTML:
{{valueAssets.name}
我遇到的问题是:
ng repeat
如何从compute()函数访问输入字段的值
通常,您可以使用自动获取输入
数据的ng模型
<div class="row" ng-repeat="(keyAssets, valueAssets) in myCurrentAssets">
<span>{{valueAssets.name}}</span>
<input data-name="myCurrentAssets[keyAssets]['name']"
data-ng-model="myCurrentAssets[keyAssets]['value']"
data-placeholder="myCurrentAssets[keyAssets]['value']"
data-ng-change="compute(myCurrentAssets[keyAssets]['value'])"
/>
</div>
{{valueAssets.name}
演示您能提供一个示例吗?如果我使用$index,它只会在输入标记的输入字段中放置一个迭代器
<div class="row" ng-repeat="(keyAssets, valueAssets) in myCurrentAssets">
<span>{{valueAssets.name}}</span>
<input data-name="myCurrentAssets[keyAssets]['name']"
data-ng-model="myCurrentAssets[keyAssets]['value']"
data-placeholder="myCurrentAssets[keyAssets]['value']"
data-ng-change="compute(myCurrentAssets[keyAssets]['value'])"
/>
</div>