在控制器绑定NG重复和NG-模型 [英] Binding ng-repeat and ng-model in controller
问题描述
这是我与我在这里这么熊的第一篇文章,我是相当新的AngularJS为好。我试图建立与NG重复的格式,并有麻烦缠绕我的头周围的角的东西。
JS在控制器:
$ scope.myCurrentAssets = {
cash_equiv:{名称:'现购自等价物',值:0,TBI:41},
投资:{名称:'短期投资',值:0,TBI:42},
notes_rec:{名称:应收票据,值:0,TBI:43},
account_rec:{名称:'应收账款',值:0,TBI:44},
盘点:{名称:'库存',值:0,TBI:45},
prepaid:{名称:'prepaid费',值:0,TBI:46},
其他:{名称:其他流动资产,值:0,TBI:47}
};
HTML
< DIV CLASS =行中myCurrentAssets(keyAssets,valueAssets)&GT纳克重复=;
<跨度> {{valueAssets.name}}< / SPAN>
<输入数据-NAME =myCurrentAssets {{keyAssets}}。
数据-NG-模式=
数据占位符={{valueAssets.value}}
数据-NG-变化=计算()
/>
< / DIV>
时遇到的问题是:
-
试图获得数据-NG-模式设置为在NG-重复的每个实例独一无二的东西
-
我怎么从计算()函数访问输入字段的值?
试图获得数据-NG-模式设置为在NG-重复的每个实例独一无二的东西。
块引用>您可以使用
列表[关键] [值]
,将每个项目的不同之处NG-重复
我怎么从计算()函数访问输入字段的值?
块引用>一般来说,你可以使用
NG-模型
自动获取输入
数据。< DIV CLASS =行中myCurrentAssets(keyAssets,valueAssets)&GT纳克重复=;
<跨度> {{valueAssets.name}}< / SPAN>
<输入数据-NAME =myCurrentAssets [keyAssets] ['名']
数据-NG-模式=myCurrentAssets [keyAssets] ['值']
数据占位符=myCurrentAssets [keyAssets] ['值']
数据-NG-变化=计算(myCurrentAssets [keyAssets] ['值'])
/>
&LT; / DIV&GT;演示<大骨节病> 小提琴 骨节病>
This is my first post on here so bear with me, I'm fairly new to AngularJS as well. I'm trying to build a form with ng-repeat and having trouble wrapping my head around the angular stuff.
JS in controller:
$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:
<div class="row" ng-repeat="(keyAssets, valueAssets) in myCurrentAssets"> <span>{{valueAssets.name}}</span> <input data-name="myCurrentAssets.{{keyAssets}}" data-ng-model="" data-placeholder="{{valueAssets.value}}" data-ng-change="compute()" /> </div>
The problems I'm having are:
trying to get the 'data-ng-model' set to something unique in each instance of the ng-repeat
how do I access the value of the input field from the compute() function?
解决方案trying to get the 'data-ng-model' set to something unique in each instance of the ng-repeat
You can use
list[key][value]
that will be different per item inng-repeat
how do I access the value of the input field from the compute() function?
Generally you can use
ng-model
that automatically fetchesinput
data.<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>
Demo Fiddle
这篇关于在控制器绑定NG重复和NG-模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!