angularjs - ng-init for drop down not working from api call -
i making call api , using response populate select drop down list. trying prepopulate select drop down box 'please choose country', countries being returned api call following isn't working guess $scope.countries.select
not defined @ stage.
html
<select ng-init="countries.select" ng-model="country" ng-change="getroles(country)" ng-options="key value (key , value) in countries"></select>
the countries object returned api call looks this:
$scope.countries = { au:"australia", be:"belgium", us:"united states" }
which push following
$scope.countries.select = "please select country";
as countries.select
not defined api response still needs returned believe reason not working.
you not initialising value of countries properly. since js doesnot know countries can not assign countries.select since countries undefined. first initialise countries empty object = {}.
however if have display default selected option of list read "please choose country" can this.
<select ng-model="country" ng-change="getroles(country)" ng-options="key value (key , value) in countries"> <option value="">please choose country</option> </select>
Comments
Post a Comment