Currently working on populating a select list in angularJS with the following code snippet:
<select class="form-control" ng-model="NewProduct.category" ng-options="category.id as category.name for category in Categories | orderBy:['name']" ng-change="update(NewProduct.category)" required></select>
When there is a change, it triggers the update function which only prints out the category ID.
$scope.update = function (value) {
alert ($scope.NewProduct.category);
};
However, I am aiming to access both the category ID and category name within this update function. I attempted:
$scope.update = function (value) {
alert ($scope.NewProduct.category.id);
alert ($scope.NewProduct.category.name);
};
Despite trying this, it keeps alerting undefined, undefined. How can I successfully obtain both the category ID and category name in the update function?