[英]Angular ng-init not called when scope variable is modified
我有一個$ scope.code.N3變量,該變量由異步ajax調用填充。
我還有一個$ scope.data.selectedIRI ,它是html組合框中選項的值。
我在表中有一個html代碼段,該變量在更新變量時將刷新:
這可以正常工作,並在需要時刷新:
<tbody>
<tr ng-repeat="t in code.N3" ng-if="t.subject==data.selectedIRI" ng-include="'displayPredicateObject'">
<!-- Rendered by template -->
</tr>
</tbody>
但是,這是行不通的(它在我的代碼的其他部分中起作用,該代碼段已集成到按角度刷新的標簽中):
<tbody ng-init="allTriples = code.N3">
<tr ng-repeat="t in allTriples" ng-if="t.subject==data.selectedIRI" ng-include="'displayPredicateObject'">
<!-- Rendered by template -->
</tr>
</tbody>
這也行不通:
<table ng-init="s = data.selectedIRI">
<tbody ng-init="triples = getTriples(null, null, s)">
<tr><td>[[triples]]</td></tr>
</tbody>
</table>
在這里從不調用getTriples(...,...,data.selectedIRI) ,而$ scope.data.selectedIRI被更新。
有什么理由嗎?
當您使用ng-init設置初始值時,$ scope.code.N3是未定義的,因為正如您所說,它是由尚未發生的異步調用設置的,這會導致ng-repeate靜默失敗
<tbody ng-init="allTriples = code.N3">
<tr ng-repeat="t in allTriples" ng-if="t.subject==data.selectedIRI" ng-include="'displayPredicateObject'">
<!-- Rendered by template -->
</tr>
</tbody>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.