當ng-repeat使用動態ng-include包含變量時,它沒有正確地使用變量。帶有動態ng-include和模板變量的ng-repeat範圍問題
看到這個plunker。
主要的html代碼
<table style>
<tr>
<th>Student</th>
<th>Teacher</th>
</tr>
<tbody ng-repeat="val in data">
<tr>
<td>
<div ng-include src="'profile.html'" onLoad="profile=val.student"></div>
</td>
<td>
<div ng-include src="'profile.html'" onLoad="profile=val.teacher"></div>
</td>
</tr>
</tbody>
</table>
profile.html代碼
<span>Id - {{profile.id}}</span>
<span>Name - {{profile.name}}</span>
您可以在鏈接看不NG-包括它的作品完美。
P.S.這是我實際嘗試實現的原型。 主要是我在動態ng-include中使用的變量存在ng-repeat中的問題。
我查看過類似的問題,但沒有得到任何答案。
你說,你不能看到下數據和NG-包括正確的? –
@SaEChowdary:是 –
ng-include會創建一個「新範圍」。 https://github.com/angular/angular.js/wiki/Understanding-Scopes#ng-include。這裏的問題是,首先你要設置option = val.student然後profile = val.teacher。個人資料越來越受到重視。你有沒有嘗試創建一個隔離範圍的指令。所以你不需要同時使用ng-include和ng-if。 –