問題:
Here is the fiddle showing the problem.這是顯示問題的小提琴。 http://jsfiddle.net/Erk4V/1/ http://jsfiddle.net/Erk4V/1/
It appears if I have an ng-model inside of an ng-if, the model does not work as expected.看來如果我在 ng-if 中有一個 ng-model,該模型不會按預期工作。
I am wondering if this is a bug or if I am misunderstanding the proper usage.我想知道這是一個錯誤還是我誤解了正確的用法。
<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>
解決方案:
參考一: https://en.stackoom.com/question/1ExpV參考二: https://stackoom.com/question/1ExpV