I am developing an application with Ionic and AngularJS. Unable to figure out how to get the value of the selected option.
controller
.controller('TestCtrl', function($scope, $options) { $scope.options = [ { id: 0, label: '15', value: 15 }, { id: 1, label: '30', value: 30 }, { id: 2, label: '60', value: 60 } ] $scope.countSelector = $scope.options[0]; $scope.changeCount = function(obj){ obj = JSON.parse(obj); console.log(obj) console.log(countSelector) $options.set('productCountPerPageValue', obj.value); $options.set('productCountPerPage', obj.id); }; ... })
Template
<ion-list ng-controller="TestCtrl"> <label class="item item-input item-select"> <div class="input-label"> {{countSelector}} </div> <select ng-model="countSelector" ng-change="changeCount('{{countSelector}}')" ng-options="opt as opt.label for opt in options"> </select> </label> </ion-list>
console.log (obj) Always return the previously selected value
console.log (countSelector) Always return the default value (if set) or undefined
source share