Angularjs ng-model在ng-if中不起作用

Angularjs ng-model在ng-if中不起作用

这是显示问题的小提琴。http://jsfiddle.net/Erk4V/1/

如果我在ng-if中有ng模型,则该模型似乎不能按预期工作。

我想知道这是一个错误还是我误解了正确的用法。

<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>


Cats萌萌
浏览 736回答 3
3回答

心有法竹

您可以使用它$parent来引用父作用域中定义的模型<input&nbsp;type="checkbox"&nbsp;ng-model="$parent.testb"&nbsp;/>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

AngularJS