2016-03-02 108 views
0

在我的表,我有NG-包括NG-表不起作用

<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

不完全清楚發生了什麼,但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子項的父範圍