带有ng-repeat的angularjs。当我使用ng-repeat时,无法访问控制器中的数据

时间:2016-03-08 17:23:44

标签: angularjs ng-repeat

我使用以下ng-model和ng-repeat,我试图访问控制器中的数据,但似乎无法访问数据。

Started by user anonymous
[Pipeline] Allocate node : Start
Running on master in /var/lib/jenkins/jobs/test/workspace
[Pipeline] node {
[Pipeline] git
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://acme/scm/app.git # timeout=10
Fetching upstream changes from https://acme/scm/app.git
 > git --version # timeout=10
 > git fetch --tags --progress https://acme/scm/app.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision fb455725db1b768ff63e627a087d2771099af7c4 (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f fb455725db1b768ff63e627a087d2771099af7c4 # timeout=10
 > git branch -a -v --no-abbrev # timeout=10
 > git branch -D master # timeout=10
 > git checkout -b master fb455725db1b768ff63e627a087d2771099af7c4
 > git rev-list fb455725db1b768ff63e627a087d2771099af7c4 # timeout=10
[Pipeline] echo
null
[Pipeline] echo
null
[Pipeline] echo
null
[Pipeline] } //node
[Pipeline] Allocate node : End
[Pipeline] End of Pipeline
Finished: SUCCESS

并使用以下ng-app

<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中的数据来动态添加控件

1 个答案:

答案 0 :(得分:0)

为了获取你应该使用的数据

   $scope.choices[index] 

索引是您要访问的索引号