javascript - Angular iterate through select options and set selected value -


i have select set states json data:

<select name="parentstate" ng-model="selectedstate" ng-options="s.stateid s.statecode s in cstates | orderby:'statecode'">     <option value="">select state...</option> </select> 

and set selected state state returned logged in user i'm entirely sure how accomplish in angular. here's i've tried , isn't working.

angular.foreach($scope.cstate, function (s) {     if (s.statecode == xparentstate) {         $scope.selectedstate = s.statecode;     } }); 

xparent state initials e.g. 'mi' michigan

the ngmodel set stateid (as seen in ngoptions - value text object in array) - set rather statecode

if (s.statecode == xparentstate) {     $scope.selectedstate = s.stateid; } 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -