angularjs - ng-init does not initialize my selected model -
i have select option list of titles i.e. mr, mrs, dr etc. api, code looks in front end:
<select class="form-control" name="titleselect" id="titleselect" ng-options="option.value option in titledata.availableoptions track option.key" ng-model="adult[$index].selectedtitle" ng-init="adult[$index].selectedtitle = titledata.availableoptions[0]"></select>
and in controller:
var getpassengertitle = passengerdetailsandcarddetailsservice.getpassengertitle();
passengerdetailsandcarddetailsservice service, api data i.e. title data. furthermore service returns promise.
this set title data:
getpassengertitle.then(function(result){ $scope.availabletitles = angular.fromjson(result.titlelist); $scope.templistoftitles = []; for(var key in $scope.availabletitles){ $scope.templistoftitles.push({key : key, value : $scope.availabletitles[key]}); }; $scope.titledata = { availableoptions: $scope.templistoftitles, }; });
when try ng-init first option (that mr.) not work in blank option shown. when tried statically defining titledata in object works, please me?
update:
i failed mention title data inside ng-repeat support input multiple people/passengers in case. therefore i'm using adult[$index] creates ng-model each person/passenger.
i not sure if required behavior want, if want initialise title on selecting option can either use value ng-model
or use event handler ng-change
. here example jsbin handles change , assigns new value ng-model. let me know if looking for
Comments
Post a Comment