我很难将变量值写入元素名称。
这里我设置动态元素名称
<tr ng-repeat="row in rowArray">
<td>
<select class="form-control" ng-model="allSelect[@{{ row }}]">
<option ng-repeat="test in [1, 2, 3, 4]" value="@{{ test }}">@{{ test }}</option>
</select>
</td>
</tr>
谢谢!
答案 0 :(得分:1)
angular.module('app', []).controller('ctrl', function($scope) {
$scope.rowArray = ['one', 'two', 'three'];
});
<script src="//code.angularjs.org/snapshot/angular.min.js"></script>
<div ng-app='app' ng-controller='ctrl'>
<table>
<tbody ng-init='allSelect={}'>
<tr ng-repeat="row in rowArray">
<td>
<select ng-model="allSelect[row]">
<option ng-repeat="test in [1, 2, 3, 4]" ng-value="test">
{{test}}
</option>
</select>
</td>
</tr>
</tbody>
</table>
allSelect: {{allSelect | json}}
</div>