html - Setting 'select' as default value in dropdown using angularjs -


i trying make simple dropdown using angularjs , want invoke function when dropdown value changed. when dropdown selection 'a', want display other elements(say 'hello') in page. here jsfiddle http://jsfiddle.net/gkjve/932/.

html

<div ng-controller="ctrl">     <select id="sel" class="input-block-level" ng-model="list_category" ng-options="obj.name obj in list_categories" ng-change="dropdownchange()">             <option value="">select</option>     </select>     <div ng-show="showdiv">       hello     </div>    <div> 

angular

var app = angular.module('app', []);     $scope.showdiv=false; function ctrl($scope) {       $scope.list_categories =  [{             id: 'id1',             name: 'a'         }, {             id: 'id2',             name: 'b'         }];              $scope.dropdownchange = function() {       $scope.showdiv = angular.equals($scope.list_category.name,'a');   } } 

result - 'hello' displayed when 'a' selected , hidden when 'b' selected. problem is, if select 'a' , change selection 'select', 'hello' still displayed. think because 'select' not 1 of model data value comparison failing. there other way make work without adding 'select' model data?

use this

<div ng-show="list_category.name == 'a'"> 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -