Reputation: 1
I am making a dropdown select to select venues in the add_event.html.
<select ng.model="venue" ng-click="getVenues()" ng-options="venue.name for venue in venues" class="form-control">
</select>
The getVenues() is in the events controller which the add_event.html uses:
$scope.getVenues = function(){
$http.get('/api/venues').then(function(response){
$scope.venues = response.data;
});
}
But for some reason the dropdown doesn't get populated?
The /api/venues does indeed produce an array of venues.
Upvotes: 0
Views: 33
Reputation: 302
<select ng-model="selectedVenue" ng-init="getVenues()" ng-options="venue.name for venue in venues track by venue.id" class="form-control">
</select>
This will allows you prepopulate data on load. keep the selectedVenue (the value to be prepopulate)
Upvotes: 0
Reputation: 222522
it should be ng-model
and use ng-init
instead of ng-click
<select ng-model="venue" ng-init="getVenues()" ng-options="venue.name for venue in venues" class="form-control">
</select>
Upvotes: 1