与指令不同
ng-show,它 创建了一个新的作用域* 。
ng-if*
因此,当您
showIt = true在内部编写内容时,
ng-if您是
showIt在子范围而非主范围上设置属性。
要解决此问题,请使用
$parent来访问父级范围内的属性:
<div ng-if="true"> <div> visibility variable: {{showIt}} </div> <div ng-show="!showIt"> <a href="" ng-click="$parent.showIt = true">Show It</a> </div> <div ng-show="showIt"> This is a dynamically-shown div. <a href="" ng-click="hideIt()">Hide it</a> </div> </div>演示柱塞。



