这里是小提琴显示的问题。
http://jsfiddle.net/Erk4V/1/
如果我在ng-if里面有一个ng-model,模型就不能按预期工作。
我想知道这是一个错误,或者如果我误解了正确的使用。
<div ng-app > <div ng-controller="main"> Test A: {{testa}}<br /> Test B: {{testb}}<br /> Test C: {{testc}}<br /> <div> testa (without ng-if): <input type="checkBox" ng-model="testa" /> </div> <div ng-if="!testa"> testb (with ng-if): <input type="checkBox" ng-model="testb" /> </div> <div ng-if="!someothervar"> testc (with ng-if): <input type="checkBox" ng-model="testc" /> </div> </div> </div>
ng-if指令与其他指令一样创建一个子范围。看到这个小提琴:
http://jsfiddle.net/Erk4V/4/
因此,您的复选框会更改子范围内的testb,而不会更改外父范围。