【发布时间】:2016-10-25 11:26:59
【问题描述】:
我是 Angular 新手,我正在尝试访问一个变量中的一些数据,其中有一个选项卡嵌套在另一个选项卡中。 (我无法链接它,因为它很敏感)。无论如何,我正在尝试使用嵌套的 ng-repeat 来访问它,但是第二个 ng-repeat 从未被调用,并且我的控制台没有给我一条错误消息。基本上是这样的。
dico = [
{ ...
content : []
},
{ ...
content : []
},
...
];
在检查了现有问题 (https://stackoverflow.com/questions/19206760/angular-nested-ng-repeat-failure#= & passing 2 $index values within nested ng-repeat) 后,我不明白为什么我的部分不起作用。
<span ng-repeat="toolbar in dico">
<candidate-toolbar-review average="toolbar.average" labeltoolbar="{{toolbar.name}}">
<span ng-repeat="field in toolbar.content" layout="row" layout-wrap layout-align="start center">
<candidate-field-review labelfield="{{field.name}}" ng-model="field.value" my-model="field.checked">
</candidate-field-review>
</span>
</candidate-toolbar-review>
</span>
在这个代码示例中,candidate-field-review 和 Candidate-toolbar-review 都是指令,如果我注释第一个,第二个将正确输出。否则,将按预期打印第一个。
我尝试使用 $parent 并通过 $index 进行跟踪,但我并不真正了解它们是如何工作的。我还尝试使用 div 代替 span 或根本不使用 span(并在候选工具栏和候选字段中包含 ng-repeats)。我在这里想念什么?谢谢!
编辑: 我改用这些线,结果很好。我仍然不知道为什么它不能反过来工作。
<span ng-repeat="toolbar in dico">
<candidate-toolbar-review ng-model="toolbar.average" labeltoolbar="{{toolbar.name}}" ng-click="showSmart=!showSmart">
</candidate-toolbar-review>
<span ng-repeat="field in toolbar.content">
<candidate-field-review labelfield="{{field.name}}" ng-model="field.value" my-model="field.checked">
</candidate-field-review>
</span>
</span>
【问题讨论】:
-
您的
candidate-toolbar-review指令是否使用transclusion? -
什么是嵌入?如果您愿意,我可以将指令的 .js 和 .html 链接给您
标签: angularjs angularjs-directive nested angularjs-ng-repeat ng-repeat