在Angularjs中嵌套ng-repeat

时间:2013-09-23 11:10:56

标签: angularjs ng-repeat

Angular Code:

$scope.qA = [ { question : ' question 1', answer: ['answer 1-1', 'answer1-2']},
              { question : ' question 2', answer: ['answer 2-1', 'answer2-2']}];

HTML(jade)代码

h1(ng-repeat='ques in qA.question') {{ques}}
 p(ng-repeat='ans in qA[$index].answer']) {{ans}}

在第一次重复重复中,我想从qA中选择“问题”。在第二次重复重复中,我想为所选的“问题”选择每个答案。

以上代码无效。怎么做到呢?

2 个答案:

答案 0 :(得分:4)

尝试:

h1(ng-repeat='q in qA') {{ q.question }}
  p(ng-repeat='ans in q.answer']) {{ ans }}

答案 1 :(得分:1)

我不知道玉,但这应该像

h1(ng-repeat='ques in qA') {{ques}}
 p(ng-repeat='ans in ques.answer']) {{ans}}