Angularjs ng-model在ng-if中不起作用這是顯示問(wèn)題的小提琴。http://jsfiddle.net/Erk4V/1/如果我在ng-if中有ng模型,則該模型似乎不能按預(yù)期工作。我想知道這是一個(gè)錯(cuò)誤還是我誤解了正確的用法。<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>
3 回答

心有法竹
TA貢獻(xiàn)1866條經(jīng)驗(yàn) 獲得超5個(gè)贊
您可以使用它$parent
來(lái)引用父作用域中定義的模型
<input type="checkbox" ng-model="$parent.testb" />
- 3 回答
- 0 關(guān)注
- 812 瀏覽
添加回答
舉報(bào)
0/150
提交
取消