I used this answer:
Working with select using AngularJS's ng-options
To try and get a dropdown list of options to fill from my AddCtrl
controller:
$scope.newMeal = {};
$scope.newMeal = {
name: "",
price: "",
ingredients: "",
description: "",
category: "",
cuisine: ""
};
$scope.categories = [
{ id: 1, name: 'Breakfast' },
{ id: 2, name: 'Lunch' },
{ id: 3, name: 'Dinner' }
];
$scope.cuisines = [
{ id: 1, name: 'Thai' },
{ id: 2, name: 'Chinese' },
{ id: 3, name: 'Italian' },
{ id: 4, name: 'British' },
{ id: 5, name: 'Spanish' },
{ id: 6, name: 'Indian' },
{ id: 7, name: 'French' },
{ id: 8, name: 'Vietnamese' },
{ id: 9, name: 'Nordic' }
];
Into my form:
<div class="list list-inset">
<label class="item item-input item-select">
<div class="input-label">
Category
</div>
<select ng-model="newMeal.category" ng-options="category as categories.name for category in categories">
<option value="" ng-if="newMeal.category"> </option>
</select>
</label>
<label class="item item-input item-select">
<div class="input-label">
Cuisine
</div>
<select ng-model="newMeal.cuisine" ng-options="cuisine as cuisines.name for cuisine in cuisines">
<option value="" ng-if="newMeal.cuisine"> </option>
</select>
</label>
</div>
However I'm getting the number of values to be filled in to be appearing, they all appear as "undefined" in the option dropdowns. How can I fix this? Note I want there to be a value of nothing if nothing is selected, and this default none value to disappear when anything is clicked.