0

The select:

select(ng-model="elId", ng-change="load(elId)", ng-options="e._id as e.name for e in options")
    option(value="") - select a mashup -

Controller:

The following works, the select gets populated. I am using broadcasts because it comes from a socket.. don't mind that.

 //receive list
 $scope.$on('list:refresh', function(ev, data) {
     $scope.options = data
 })

The following only works if I did not manually select any option before. data.id is a valid entry in the list.

 //refresh list of mashups when a new one has been created
 $scope.$on('list:select', function (ev, data) {  
     $scope.elId = data.id
 })

If I manually select an option, and then the list:select fires, the $scope.elId is udated but the <select> does not highlight the option.

What is going on?

2
  • 1
    Your issue appears to be the fact that you're not utilizing the ng-selected directive. Check out the docs here Commented Aug 23, 2013 at 16:21
  • that cold be a problem, too.. but not in this case, see my answer :) thanks though Commented Aug 23, 2013 at 16:36

1 Answer 1

1

Solved:

The select:

select(ng-model="data.elId", ng-change="load()", ng-options="e._id as e.name for e in options")
    option(value="") - select a mashup -

Controller:

 //receive list
 $scope.$on('list:refresh', function(ev, data) {
     $scope.options = data
 })

 $scope.load() {
    var elId = $scope.data.elId
    ....
 }

 //refresh list of mashups when a new one has been created
 $scope.$on('list:select', function (ev, data) {  
     $scope.data.elId = data.id
 })

I guess the problem was that I tried to change the selected value from a child controller.. now I am using a service Data that I load into the controllers $scope.data = Data.. meh?

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

3 Comments

I think what solved the issue is you changing the ng-model from a simple variable to the property of an object. This seems like a common problem with ng-model in angular. I have fought it a few times.
Oh, I see - gotta remember that! :) Just lost few hours for that problem :P
I know, me too. That has to be high on the list of Angular gotchas.

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.