1

I have a code of SELECT element like this

 select(ng-model="chosenProject" id="chosenProject"  ng-options="c.name for c in selectItems")

where selectItems are arrays of objects, and each object got name and value fields. Later in chosenProject.value I read an object (with value and name fields) of chosen item.

Now I also need to pre-select some element based on its value. If I do $scope.chosenProject.value=*somevaluenumber*, $scope.chosenProject.value.value =*somevaluenumber* it does not seem to work.

I can not change the declaration; chosenProject gets the whole object of selected item and that's what I use later in code.

Eduard Gamonal
  • 8,023
  • 5
  • 41
  • 46
onkami
  • 8,791
  • 17
  • 90
  • 176

2 Answers2

2

Try this

angular.forEach($scope.selectItems, function(value){
    if(value.value == someValue){
          $scope.chosenProject = value;
          $scope.$apply();
    }
})

Demo: http://plnkr.co/edit/FSO2zi96AUbVpWG3v092?p=info

nimesh89
  • 98
  • 5
  • Somehow still do not work at my end, thought I am going to approve the answer as it works in plnkr :) Any ideas why it is still not fuinctioning? – onkami Apr 25 '14 at 08:48
  • Need more information to see why its not working in your project. – nimesh89 Apr 25 '14 at 09:41
0

If you want to set each option with an value, you should try use this: How do I set the value property in AngularJS' ng-options?

Community
  • 1
  • 1
Bruno Gomes
  • 1,435
  • 1
  • 11
  • 14