Unable to set selected value in AngularJS -


i have several select boxes on edit form, when page loads data loaded it, works textboxes , checkboxes not selectboxes, unable set selected value them have googled many things still cannot seem find doing wrong, html:

<div class="form-group" ng-init="getroles()">     <label for="roles">role</label>     <select style="width: 100%;" data-toggle="select2"  ng-model="form.role_id" ng-options="item.id item.role item in roles">     </select> </div> 

this function gets , sets user info in controller:

$scope.getuserinfo = function() {      userservice.get($stateparams.id)         .success(function (data, status, headers, config) {             if (data.user != undefined)             {                 $scope.form = data.user;             }         })  }; 

this function gets , sets roles in controller:

$scope.getroles = function() {      roleservice.get()         .success(function (data, status, headers, config) {             if (data.roles != undefined)             {                 $scope.roles = data.roles;             }         })   }; 

i have verified returned data , indeed correct. returned json:

{"user":{"id":2,"email":"xxxxxxx@gmail.com","role_id":2,"institution_id":null,"is_active":1}} 

and returned roles json:

{"roles":[{"id":2,"role":"system"},{"id":3,"role":"administrator"},{"id":4,"role":"instructor"}]} 

you need write

ng-model="user.role_id"


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -