ng-include在ng-table中不起作用

时间:2016-03-02 02:29:39

标签: javascript angularjs ngtable

在我的表格中,我有

<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放在同一视图中,那么它就能正常工作。

1 个答案:

答案 0 :(得分:1)

不完全清楚发生了什么,但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子的父范围