Search code examples
angularjsangularjs-ng-options

Assign an object in a select in angularjs


I modified the original plunker of

original documentacion ng-options

I am trying to assign in the "bogus" button the black object.

It is the same object but is not selected in the drop down with ng-model binding

{name:'black', shade:'dark'}

you can see in

plunker forked

Why the double binding is not working???


Solution

  • It's because it's not the same object, try using a filter to get your black item as in this plunker

    $filter('filter')($scope.colors, {name : 'black'});
    

    If you use a console.log of the $filter black item you'll see there is a $$hashKey: "object:3" value added to the item, that's why it doesn't take it as the same object.