我不想使用 $index 来创建一个新的 $scope 变量:
<div ng-repeat="i in items track by $index">
<input autocomplete="off" type="text"
ng-model="myVariableName{{$index}}" >
....
我不想声明变量:myVariableName0、myVariableName1 等...
最佳答案
在 Controller 中声明空对象
$scope.myVariableName = {};
并在模板中将模型值分配为对象的属性。
ng-model="myVariableName[$index]"
关于javascript - 如何在使用 $index 时动态定义 ng-model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47528443/