How to get select2 value in AngularJs -


i not able value of select2. code:

<select id="categoryid" class="category"                                     ng-model="selectedcategory"                         ng-options="selectedcategories.name selectedcategories in categories"                         ng-change="selectedcategory()">                         <option></option>                     </select> 

in controllers wrote this:

    .....      function initializeselect2 (){         $category.select2({                 allowclear: true         });    }     $scope.selectedcategory = function (){         console.log('selectcategory: '+ $scope.selectedcategory);        } 

for versions of select2 before 4.0.0, recommended drop select2 , use ui-select (not ui-select2) angularjs-native version of select2. select2 4.0.0 works angularjs though (as needs to), no longer strictly necessary use ui-select.

the problem here dom change event (which triggered select2) different angularjs change event, listening to. angularjs change event triggered whenever value of ng-model changes, in case might not when expecting it.

your ng-model doesn't contain dot (.) in it, means angular not going able listen changes , might never detect them. 1 fixable explanation why ng-change handler might not triggered.

the other reason might select2 half-destroyed in digest cycle, leave select2's dom sitting in pieces around page event handlers wouldn't working expected. noticeable dropdown not opening or closing, suspect might not issue.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -