How to show a form field ONLY if another is selected in angularjs

angularjs

Solution

Simple as hell. When red is selected, the value of `form.add.color` will be `'red'`. Whereas when green is selected, its value will be `'green'`.

So you just need to use the `ngShow` directive on the divs you want to show/hide based on the selection:

<div class="form-group" ng-show="form.add.color == 'red'">

or

<div class="form-group" ng-show="form.add.color == 'green'">

Problem

I have the following html code: ``` <div class="form-group"> <label class="control-label col-sm-2" for="inputColor">Collor</label> <div class="col-sm-6"> <input type="radio" ng-model="form.add.color" name="color" value="red"> red <input type="radio" ng-model="form.add.color" name="color" value="green"> green </div> </div> <div class="form-group"> <label class="control-label col-sm-2" for="inputProbleme">Problème</label> <div class="col-sm-6"> <input type="text" class="form-control" id="inputProbleme" ng-model="form.add.probleme" name="probleme" placeholder=""> </div> </div> <div class="form-group"> <label class="control-label col-sm-2" for="inputDate">Date</label> <div class="col-sm-6"> <input type="date" class="form-control" id="inputDate" ng-model="form.add.date" name="date" placeholder=""> </div> </div> <div class="form-group"> <label class="control-label col-sm-2" for="inputService">Service</label> <div class="col-sm-6"> <input type="number" class="form-control" id="inputService" ng-model="form.add.service" name="service" placeholder="123..."> </div> </div> <div class="form-group"> <label class="control-label col-sm-2" for="inputVu">Vue</label> <div class="col-sm-6"> <input type="radio" ng-model="form.add.vu" name="vu" value="true"> True <input type="radio" ng-model="form.add.vuD" name="vu" value="false"> False </div> </div> ``` So what I want to do here is, when I select "red", the form will show "proleme" and "date" inputs to fill in, and when I select green it will show "service" and "vue". I know that we can do that using jquery or javascript, but how to do with Angularjs?

Original source