ng-include in ng-table 不起作用

ng-include in ng-table doesn't work

本文关键字:不起作用 ng-table in ng-include      更新时间:2023-09-26

在我的表格中,我有

<tr
  ng-repeat="question in $data"
  ng-include="'/views/partials/questionList.html'"></tr>

questionList.html,我有:

<td class="top-td" data-title="'ID'" sortable="'id'">
  <a href="#" ng-click="loadQuestionModal(question.id)">
    {{ question.id }}
  </a>
</td>
<td class="top-td" data-title="'Question / Instruction'">
  <h6 markdown-to-html="question.Instruction.instructionText"></h6>
  <blockquote ng-show="k8englishSubject" markdown-to-html="question.questionText"></blockquote>
  <blockquote markdown-to-html="question.questionText" mathjax-bind="question.questionText" ng-show="k8mathSubject"></blockquote>
</td>
<td class="top-td"><ng-include src="'/views/partials/answerList.html'"></ng-include></td>
<td class="top-td" ng-show="k8englishSubject">
  <a ui-sref="passages.upsert({passageId: question.PassageId})" ng-show="question.PassageId">
    {{ question.Passage.passageTitle }}
  </a>
</td>
<td class="top-td" data-title="'Level'" sortable="'level'">{{ question.level }}</td>

但是,这不会呈现任何标题。但是,如果我有一个常规tr并将td放在同一个视图中,那么它就可以了。

不完全清楚发生了什么,但ng-repeatng-include都创建了子作用域。

我建议你用你自己的指令替换ng-include以避免额外的子范围

<tr  ng-repeat="question in $data" my-directive></tr>

.JS

app.directive('myDirective',function(){
    return {
         restrict:'A',
         templateUrl:'/views/partials/questionList.html';
     };
});

就目前而言,该指令的唯一功能是提供模板,它将在每次迭代中继承ng-repeat子项的父范围