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.

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

2 Comments

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?
Need more information to see why its not working in your project.
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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.