Is there a way I can use conditional AngularJS data binding?
I want to bind my model to vm.ABC if bool has true value, if it has false, I want to bind my model to vm.XYZ.
Is there a way I can use conditional AngularJS data binding?
I want to bind my model to vm.ABC if bool has true value, if it has false, I want to bind my model to vm.XYZ.
You can use ng-if for this. Here is the simple example,
//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' />
This will work great for your condition. And also by using ng-if the HTML is not render on the UI if the condition is false.
<div ng-init="vm.thirdVar = bool ? vm.ABC : vm.XYZ">
<input type="text" ng-model="vm.thirdVar">
</div>
vm.thirdVar define this in controller