Below is the code that I am currently using:
<select ng-model="setPriceClass"
ng-options="price as price.label for price in priceClass">
</select>
function ExampleCtrl($scope) {
$scope.priceClass = [
{'label': 'label1', 'value': '1'},
{'label': 'label2', 'value': '2'},
{'label': 'label3', 'value': '3'},
{'label': 'label4', 'value': '4'}
];
$scope.setPriceClass = $scope.priceClass[0];
}
In ng-route: ExampleCtrl as example
The select field displays my priceClass object. Now, I am attempting to use "vm." instead of "$scope.", but I am unable to make it display the priceClass in my select field.
I have tried the following:
<select ng-model="example.setPriceClass"
ng-options="price as example.price.label for price in example.priceClass">
</select>
function ExampleCtrl() {
var vm = this;
vm.priceClass = [
{'label': 'label1', 'value': '1'},
{'label': 'label2', 'value': '2'},
{'label': 'label3', 'value': '3'},
{'label': 'label4', 'value': '4'}
];
vm.setPriceClass = vm.priceClass[0];
}
How can I correctly set the ng-options?