无法访问范围

时间:2016-11-02 19:56:56

标签: angularjs

我无法在范围内显示ng-model的值。 “radiovalue [$ parent。$ index]”这段代码不返回任何值。 即时通过角色

从php获取数组
html:

         <div ng-repeat="question in set" ng-if = "question.type === 'multiple'">
       <div class="shadow">
         <ul>
           <li><div class="question">{{question.question}}</div></li>
           <div id="multiple" ng-repeat="choice in question.questiontype.choice"><input type="radio" ng-name="question.type" ng-model="radiovalue[$parent.$index.choice]" ng-value="choice">{{choice}} </div>
         </ul>
       </div>
     </div>


Controller:
 $rootScope.radiovalue = [];
  console.log($rootScope.radiovalue);

PHP:
structure of the array
      $json['questionid'] = $value['questionid'];
      $json['question']   = $value['question'];
      $json['type']       = $value['type'];
      $json['questiontype']['choice']['a'] = $valueb['mc1'];
      $json['questiontype']['choice']['b'] = $valueb['mc2'];
      $json['questiontype']['choice']['c'] = $valueb['mc3'];
      $json['questiontype']['choice']['d'] = $valueb['mc4'];

伙计们新问题:      数组长度的输出不正确。它显示数组长度为5,尽管它有2个已定义的数组元素。我在这里有羽毛http://plnkr.co/edit/RfmK0s3FZIR0qziultEJ?p=preview

1 个答案:

答案 0 :(得分:0)

不应该:

ng-model="radiovalue[$parent.$index].choice"

其次,只有当$parent.$index内有ng-repeat时才能获得ng-repeat ... nested ng-repeat ...然后才有意义。