Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
angularjs和ng重复。使用ng repeat时无法访问控制器中的数据_Angularjs_Ng Repeat - Fatal编程技术网

angularjs和ng重复。使用ng repeat时无法访问控制器中的数据

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

我使用以下带有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 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]