我在视图文件中有以下内容:
<p class="presentation black">Sections:
<span data-ng-if="currentTab == 'tab1'">
<div ng-repeat="question in filtered = (template.questions | unique:'sectionName')"></div>
<p class="presentation black">{{filtered.length}}</p>
</span>
<span data-ng-if="currentTab == 'tab2'">
<div ng-repeat="sheet in filtered = (template.sections[0].sheets | unique:'name')"></div>
<p class="presentation black">{{filtered.length}}</p>
</span>
</p>
选择tab1
时,信息会正确显示。但是,在tab2
上时,似乎正在显示两个范围中的<p>
元素 - 显示与<p>
相关的tab1
元素的空值。通过查看DOM树,似乎在tab2
时,ng-if
条件未显示:<!-- end ngIf: currentTab == 'tab2' -->
。任何人都可以看到问题出在哪里?如果需要更多代码,请告诉我。
答案 0 :(得分:1)
&#34; p&#34;不应该在&#34; span&#34;根据HTML5规范。改变&#34; span&#34;到了&#34; div&#34;。
HTML
<p class="presentation black">Sections:
<div data-ng-if="currentTab == 'tab1'">
<div ng-repeat="question in filtered = (template.questions | unique:'sectionName')"></div>
<p class="presentation black">{{filtered.length}}</p>
</div>
<div data-ng-if="currentTab == 'tab2'">
<div ng-repeat="sheet in filtered = (template.sections[0].sheets | unique:'name')"></div>
<p class="presentation black">{{filtered.length}}</p>
</div>
</p>