当我在输入字段中输入值时,我无法绑定模型数组中的值而无法在$scope.selectfield[$index]
中访问。
以下是Html代码的一部分:
var ap = angular.module("myapp", []);
ap.controller("membercontroller", function($scope, $http, $window) {
$scope.selectfield = [];
$scope.dropdown = ["abc", "xyz", "pq", "aqz"];
})

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular.min.js"></script>
<div ng-app="myapp" ng-controller="membercontroller">
<div class="col-lg-6">
<label id="billamt"> Select Members:</label>
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="checkbox" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria- expanded="true">
Select members
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li ng-repeat="z in dropdown">
<a href="#">
{{z}}
<br>
<input type="number" ng-model="selectfield[$index]" value="{{selectfield[$index]}}"/>
</a>
</li>
</ul>
</div>
</div>
</div>
&#13;
答案 0 :(得分:0)
$ index未定义。尝试将'track by $ index'添加到ng-repeat。