javascript - Angular Model value is not updated when select value changes -


i have following code in controller

$scope.currencies = [     { "currency_code": "usd", "currency_name": "american dollar" },     { "currency_code": "aud", "currency_name": "australian dollar" },      { "currency_code": "brl", "currency_name": "brazilian real" },      { "currency_code": "cad", "currency_name": "canadian dollar" },      { "currency_code": "chf", "currency_name": "swiss franc" },      { "currency_code": "clp", "currency_name": "chilean peso" } ]  $scope.selectedcurrency = "usd";  $scope.dostuffs = function(){    alert($scope.selectedcurrency); } 

and in view

<div class="selected_currency">{{selectedcurrency}}</div> <select id="currency" name="currency" ng-model="selectedcurrency"  ng-options="currency.currency_code currency.currency_code currency in currencies">  </select> 

problem

when change currency select, , execute dostuffs() function, alerts default value usd, model selectedcurrency not taking changed value.

however expression {{selectedcurrency}} works pretty well.

can tell me how update model when select value changes?

thanks

update

this didn't work

<ion-view view-title="my stuffs" ng-controller="myctrl">     <ion-content>             <!-- other tags -->     </ion-content> </ion-view> 

however, following code worked (i defined ng-controller directive in ion-content tag)

<ion-view view-title="my stuffs">         <ion-content  ng-controller="myctrl">                 <!-- other tags -->         </ion-content>     </ion-view> 

just add ng-change="dostuffs()" in select element

<select     id="currency"     name="currency"     ng-model="selectedcurrency"     ng-change="dostuffs()"    ng-options="currency.currency_code currency.currency_code     currency in currencies">  </select> 

please demo here https://plnkr.co/edit/1guefbhkkrrqmrisotyb?p=preview


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo