[英]Cascading expression in AngularJS works with ng-show but not with ng-if
如果我使用ng-show
顯示部分而不是所需的ng-if
下面的代碼塊可以工作
<div ng-controller="nullController">
<button ng-click="p = 1">click to reveal next</button>
</div>
<div ng-show="$$prevSibling.p == 1" ng-controller="nullController">
<div>Appears based on previous sibling state</div>
<button ng-click="p = 1">click to reveal next</button>
</div>
<div ng-show="$$prevSibling.p == 1" ng-controller="nullController">
<div>Appears based on previous sibling state</div>
<button ng-click="p = 1">click to reveal next</button>
</div>
更新:有人指出木板中的angularjs lib的版本沒有ng-if。 現在我已更新使用1.2.x問題然而沒有消失。
您正在使用angularjs 1.0.1 !
ng-if
在這個舊版本中還不存在。
只有1.1.5以上版本才能處理ng-if
指令。
你真的應該為你的plunkr選擇這個版本(最新的穩定版本):
<script data-require="angular.js@1.2.16" data-semver="1.2.16" src="https://code.angularjs.org/1.2.16/angular.js"></script>
這里有更多官方數據顯示ngIf
自1.1.5起可用。
此外,請注意ngIf
創建一個新的子范圍。 實際上,它需要這種機制才能實現從DOM中刪除組件。 ng-show
不需要它,因為它只是隱藏內容。
因此, $$prevSibling
不會以預期范圍為目標,因為從范圍層次結構中的更深范圍調用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.