e-Designary e-Designary - 1 year ago 106
AngularJS Question

Show input field based on ng-if condition

I've two radio buttons VAT & CST and one input field. If I select VAT the input field should appear and if I select input field should be hidden. How to do it in angularJS. Thank You!

Here is my code

<input type="radio" ng-model="vat" name="source" value="VAT"> VAT
<input type="radio" name="source" value="CST"> CST

<input type="number" ng-if="vat" placeholder="Gunny VAT">

Answer Source

Use ng-model.

<input type="radio" ng-model="flag" name="source" value="VAT"> VAT
<input type="radio" ng-model="flag" name="source" value="CST"> CST

<input type="number" ng-if="flag == 'VAT'" placeholder="Gunny VAT">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download