Wednesday, 15 January 2014

javascript - Angular chosen is not binding Array of Objects -



javascript - Angular chosen is not binding Array of Objects -

i'm using angular choosen plugin selecting attribute on select element.

my info in format:

$scope.pets = [ { id: '1', name: 'dog', desc:"something" }, { id: '2', name: 'cat', desc:"something" }, { id: '3', name: 'rat', desc:"something" } ];

and angular choosen implementation displaying name using ng-options is:

<select multiple ng-model="mypets" ng-options="r r.name r in pets" chosen>

i'm able drop downwards using ng-options above info this,

but how can bind default values angular choosen input box if ng model bind next object:

$scope.mypets= { id: '6', name: 'pig', desc:"something" },

you can set default values in controller using

$scope.mypets= [$scope.pets[0], $scope.pets[5]];

compared thinking need utilize array [] because using select multiple. have straight refer existing objects or angular/javascript won't recognize connection.

javascript angularjs

No comments:

Post a Comment