angularjs和ng重复。使用ng repeat时无法访问控制器中的数据
我使用以下带有ng repeat的ng模型,并尝试访问控制器中的数据,但似乎无法访问控制器中的数据angularjs和ng重复。使用ng repeat时无法访问控制器中的数据,angularjs,ng-repeat,Angularjs,Ng Repeat,我使用以下带有ng repeat的ng模型,并尝试访问控制器中的数据,但似乎无法访问控制器中的数据 <div ng-controller="myCtrl" class="container"> <fieldset data-ng-repeat="contact in choices"> <input class="form-control" ng-model='contact.firstname'> <input
<div ng-controller="myCtrl" class="container">
<fieldset data-ng-repeat="contact in choices">
<input class="form-control" ng-model='contact.firstname'>
<input class="form-control" ng-model='contact.lastname'>
<input class="form-control" ng-model='contact.email'>
<input class="form-control" ng-model='contact.contact'>
<input class="form-control" ng-model='contact.adress'>
<input class="form-control" ng-model='contact.city'>
<input class="form-control" ng-model='contact.state'>
<button class="btn btn-primary" ng-click="addcontact()">Add</button></td>
</fieldset>
<button class="addfields" ng-click="addNewChoice()">Add fields</button>
<div id="choicesDisplay">
{{ choices }}
</div>
</div>
</div>
</div>
我无法通过ng repeat访问动态添加控件的$scope中的数据,以便访问您应该使用的数据
$scope.choices[index]
Index是您要访问的索引数,但我正在动态添加控件,因此我如何知道Index的值?您必须在函数中添加索引,例如,如果要在addcontact函数中获取索引,它必须类似于addcontact(contact.$Index)在htmlif中,如果您想获得最新版本,那么在控制器中,您必须使用var index=$scope.choices.length-1;然后使用$scope.choices[index]
$scope.choices[index]