javascript - How to select an option in angular js when options are fetched from an api -
i have app has connected select box state,city. have feed state name , city name controller. not able find out way.
<label>state</label> <select ng-change="cities(state);" class="form-control" ng-model="state" required> <option selected>select</option> <option ng-repeat="x in state" value="{{x.state}}">{{x.state}} </option> </select> <label>city</label> <select class="form-control" ng-model="city" ng-change="location(city);" required> <option selected>select</option> <option ng-repeat="y in cities" value="{{y.city}}">{{y.city}} </option> </select> i tried code in controller not work.
$scope.state=response.data.state; $scope.city=response.date.cities; thanks in advance.
assign ng-repeat array different name:
$scope.states=response.data.state; $scope.cities=response.date.cities; need have ng-model of select in different name:
<label>state</label> <select ng-change="cities(state);" class="form-control" ng-model="state" required> <option selected>select</option> <option ng-repeat="x in states" value="{{x.state}}">{{x.state}} </option> </select> <label>city</label> <select class="form-control" ng-model="city" ng-change="location(city);" required> <option selected>select</option> <option ng-repeat="y in cities" value="{{y.city}}">{{y.city}} </option> </select>
Comments
Post a Comment