有没有一种方法可以使用条件 AngularJS 数据绑定(bind)?
如果 bool 值为真,我想将我的模型绑定(bind)到 vm.ABC
,如果它为假,我想将我的模型绑定(bind)到 vm.XYZ
。
最佳答案
您可以为此使用 ng-if
。这是一个简单的例子,
//if bool is true then bind vm.ABC
<input type='text' ng-if='bool' ng-model='vm.ABC' />
//if bool is false then bind vm.XYZ
<input type='text' ng-if='!bool' ng-model='vm.XYZ' />
这对您的情况很有帮助。此外,如果条件为 false
,则通过使用 ng-if
,HTML 不会呈现在 UI 上。
关于javascript - 条件 AngularJS 模型绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46073597/