Angular JS ng-show/ hide based on drop-down list selected value
NickName:Max Ask DateTime:2015-02-16T04:25:10

Angular JS ng-show/ hide based on drop-down list selected value

in the following code I have one drop-down list (serviceSmallId) for type of service. It is populated using model info.

There is a second field check-box which should only be visible when drop-down has a selected value of 'Weekly'. I am trying to use ng-show/ hide of angular.

I tried to search for possible solutions but no luck. Can anyone please guide me what I am doing wrong.

<section id="scrubber-view" class="mainbar" data-ng-controller="scrubber as vm">
    <section class="matter">
        <div class="container">

            <div>
                <button class="btn btn-info" ng-click="vm.goBack()"><i class="fa fa-arrow-left"></i>Back</button>
                <button class="btn btn-info" ng-click="vm.cancel()" ng-disabled="!vm.canSave"><i class="fa fa-undo"></i>Cancel</button>
                <button class="btn btn-info" ng-click="vm.save()" ng-disabled="!vm.canSave"><i class="fa fa-save"></i>Save</button>
                <span ng-show="vm.hasChanges" style="color:orange" class="dissolve-animation ng-hide"><i class="fa fa-asterisk"></i></span>
            </div>

            <div class="row">
                <div class="widget wblue">
                    <div data-cc-widget-header title="{{vm.title}}" subtitle="{{vm.scrubber.scrubberId}}"></div>

                    <form class="form-horizontal">

<div class="form-group">
                            <label for="serviceSmallId" class="col-sm-2">Service</label>
                            <div class="col-sm-4">
                                <select class="form-control" id="serviceSmallId" ng-model="vm.scrubber.serviceSmallId"
                                        ng-options="item.dataLookupId as item.description for item in vm.serviceSmalls | orderBy:['sortOrder','description']">
                                </select>
                            </div>
                        </div>



 <div class="form-group" ng-show="vm.scrubber.serviceSmallId.value=='Weekly'">
                            <input class="form-control" type="checkbox" id="fullyFlanged" value="Bar" />
                        </div>

 </form>
                </div>
            </div>
        </div>
    </section>
</section>

Copyright Notice:Content Author:「Max」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/28530743/angular-js-ng-show-hide-based-on-drop-down-list-selected-value

Answers
Michael Coleman 2015-02-15T20:57:42

There probably is a more elegant \"angular way\" solution, \n\nbut I updated you code to work here - http://jsbin.com/tupisoriho/1/edit?html,js,output\n\nExplanation of changes\n\n\nProvided ng-show a value vm.checker \nadded ng-change to the select element and gave it a function checkerGo which tested to see if dropdown == 'weekly', if yes change vm.checker \n\n\nUpdate\n\nthere is a more \"angular way\" - using expressions!\nAs per @Omri Aharon fiddle/comment below.",


More about “Angular JS ng-show/ hide based on drop-down list selected value” related questions

Angular JS ng-show/ hide based on drop-down list selected value

in the following code I have one drop-down list (serviceSmallId) for type of service. It is populated using model info. There is a second field check-box which should only be visible when drop-do...

Show Detail

Get selected value from a drop-down list in Angular

I am pretty new to Angular and have a requirement where I need to read the selected value from a drop-down list and send the selected value to a component while routing. Can someone tell how do I e...

Show Detail

Update text field based on selection in drop-down list(Angular JS)

I am trying to create a drop-down list using angular-Js. The element that is coming should be currently selected in drop-down list is coming from some databse.(Initialized as $scope.choice = "two",...

Show Detail

How to automatically set a value in drop-down list based on a value from another drop-down list

I have a googlesheet with Columns A - P. Column B (GROUP) is a dropdown list and Column N (EXECUTION STATUS) is a drop-down list. I am trying to automatically set a particular value in a cell for ...

Show Detail

drop-down not getting selected with the selected value in angular js

I am using drop-down in ng-repeat in angular js, and my HTML code is &lt;select class="form-control" ng-model="l.Language" ng-change="languageChange($index, l.Language)" ng-options="L.ID as L.

Show Detail

Drop-down list in drop-down box disappears Angular 5

I have a form in Angular 5 or when I select a value in a drop-down list it displays another one. The trouble is that when I select (see link) in the first drop-down list the value 'two' and I select

Show Detail

NG-show based on select list

I am trying to get items to only show up if something is selected in a select list. I am trying something like this &lt;input ng-show="myDropDown==''" type="text"&gt; I basically want logic sayi...

Show Detail

Angular ng-show does not show/hide based on function return value

So my angular app is a behemoth, so I pasting the relevant parts here just to see if the Angular Gurus at SO can spot anything that can help me. I have my HTML code like so: &lt;span class='span_...

Show Detail

Angular 4 ng-show

I need to hide and show a textbox based on the value selected in the drop-down. This is already done in Angular 1, but how to do it in Angular 4. &lt;div ng-app ng-controller="Controller"&gt; ...

Show Detail

How to set a selected option of a dropdown list control using angular JS

I am using Angular JS and I need to set a selected option of a dropdown list control using angular JS. Forgive me if this is ridiculous but I am new with Angular JS Here is the dropdown list cont...

Show Detail