Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ng-option in 1.3 does not select ng-model (with decimal value) when the collection is set asyncronously #11184

Closed
pramodsankarl opened this issue Feb 26, 2015 · 4 comments

Comments

@pramodsankarl
Copy link

As a follow up on my own post on stackoverflow submitting an issue here.

Problem statement
After upgrading to 1.3 version, there seems to be an issue with ng-option directive with ng-model. When the model is set prior to the asynchronously set collection bound to the ng-option and when the model is a decimal value (works fine with integer).Rendered select seems to display as nothing has been selected. No issue in FF, i see issue in IOS safari, IE and chrome at least.

As you can see here:

.controller('MainCtrl', function($scope , $timeout) {
   $scope.selected = {item: 2.5}; //setting an integer options works just fine example item:2
   //Returns a promise which is resolved with the data/async call simulation
   function getData(){
     return $timeout(function(){
       return [{value:"0",id:0},{value:"0.5",id:0.5},{value:"1",id:1},{value:"1.5",id:1.5},{value:"2",id:2},{value:"2.5",id:2.5},{value:"3",id:3}]
     });
   }

  getData().then(function(data){
      $scope.items = data;  
  });
});

and

<select ng-model="selected.item" ng-options="item.id as item.value for item in items"></select>

Some observations:

  • Using track by item.id works fine.
  • Setting ng-model only along with setting the collection works fine too.
  • 2 options are getting selected attribute on DOM inspection (of the rendered select options) of issue scenario.
  • Works fine when id is as string as well. Same issue even if it is a string, "2" works but "2.5" doesn't.
  • If you switch back to angular 1.2.x this works just fine
@rinatio
Copy link

rinatio commented Mar 2, 2015

Having same issue with strings

Works fine when id is as string as well.

@pramodsankarl It works there because you set selected after timeout.

@pramodsankarl
Copy link
Author

@rinatio Thanks for pointing that out, Yes you are right. It seems weird in that case as well, "2" works "2.5" does not. I have not got a chance to debug in yet.

@Narretz
Copy link
Contributor

Narretz commented Sep 13, 2015

#11835 (comment)

@Narretz Narretz closed this as completed Sep 13, 2015
@Narretz
Copy link
Contributor

Narretz commented Sep 13, 2015

We've decided not to fix this issue. See #11835 (comment) for more info

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants