[英]Can I use {{variable name}} in ng-model on angular 1.x
I have this source 我有这个来源
<tr ng-repeat="value in item.info_group">
<td class="text-center"><input type="radio" value="{{value.carrier}}" ng-model="item.select_carrier" ng-change="calcAllPrice()"></td>
<td class="text-center">{{value.carrier}}</td>
<td class="text-center">
<select class="form-control" ng-model="item.info_group['{{value.carrier}}']">
<option value="{{carrier_info.carrier_type}}" ng-repeat="carrier_info in value.value">{{carrier_info.carrier_type}}({{carrier_info.charge}})</option>
</select>
</td>
</tr>
I wanna use {{variable}} in ng-model like ng-model="item.info_group['{{value.carrier}}']" 我想在ng-model中使用{{variable}},例如ng-model =“ item.info_group ['{{value.carrier}}']”
Can I use like that? 我可以这样使用吗?
Thank you. 谢谢。
您不需要大括号,您可以这样做:
ng-model="item.info_group[value.carrier]"
As Michael said, you don't need the curly brackets inside ng-model
. 正如迈克尔所说,您不需要ng-model
内的花括号。 The reason being that the {{var}}
syntax is used for one-way data-binding (ie $scope
-> view). 原因是{{var}}
语法用于单向数据绑定(即$scope
> view)。 The ng-model
directive sets up a two-way binding on form elements (ie $scope
-> view and view -> $scope
). ng-model
指令在表单元素(即$scope
> view and view-> $scope
)上建立双向绑定。
In your particular case you want a two way binding on the item from array item.info_group
with the index value.carrier
and don't need to use any {{var}}
syntax to achieve that. 在您的特定情况下,您需要对索引为value.carrier
数组item.info_group
的项目进行双向绑定,而无需使用任何{{var}}
语法来实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.