angularjs - Get ng-model value from inside ng-repeat using ng-change -


guys new angular , having problems getting value of ng-model inside ng-repeat.

i have array of users, , want appoint users different access levels

users = [ {id:1, level:0}, {id:2, level:0}, {id:3, level:0} ] 

this html

<div ng-repeat="user in users track $index"> {{user.id}}- <select name="appoint" ng-change="appoint(user.id)" ng-model="appointlevel">    <option value=0>revoke</option>    <option value=1>moderator</option>    <option value=2>admin</option>  </select> </div> 

the appoint() function in angular:

$scope.appoint = function(id){     console.log(id+' '+appointlevel)   } 

the function working fine , getting value of id not `appointlevel' of input element has triggered function.

how can value console.log(id+' '+appointlevel) efficiently on `ng-change'? in advance.

use

<select name="appoint" ng-change="appoint(user.id, appointlevel)" ng-model="appointlevel"> 

and

$scope.appoint = function(id, appointlevel) {     console.log(id + ' ' + appointlevel); } 

you can't access appointlevel js function directly, because it's in scope of ng-repeat, child scope of controller scope (i.e. $scope).

working plunker

or store appointlevel in user itself:

<select name="appoint" ng-change="appoint(user)" ng-model="user.appointlevel"> 

and

$scope.appoint = function(user) {     console.log(user.id + ' ' + user.appointlevel); } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -