Angular Ng-options With Preselected Value By Object Id
Is there a way the following select can have a pre-selected club ?
Solution 1:
in the controller set the ng-model of the select to the value of the option you want selected. Something like : $scope.c.pilot.clubIdx = 2
or $scope.c.pilot.clubIdx = $scope.c.clubs[1].idx
Solution 2:
<select ng-model="c.pilot.clubIdx" ng-options="club.idx as club.name for club in c.clubs track by club.idx" ng-selected="(club.idx == 2)?true:false">
add ng-selected like so. It should be preselected
Solution 3:
using underscore/lodash use the following lines in controller:
var club =_.where(c.clubs, {name:"club2"});
$scope.c.pilot.clubIdx = club.idx;
Solution 4:
removing the track by clause solves the problem. i dont fully understand why, but who knows. angular doc for ngOptions
Post a Comment for "Angular Ng-options With Preselected Value By Object Id"