I have a dropdown that allows the user to select a number.
<body ng-app="myApp">
<div ng-controller="MyCtrl">
<select ng-model="selectedNum" ng-change="numberSelected()">
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="40">40</option>
<option value="50">50</option>
</select>
</div>
</body>
Back in my controller, I can reference the selected value via $scope.selectedNumber
angular.module('myApp', []).controller('MyCtrl', function($scope) {
$scope.selectedNum = 10;
$scope.numberSelected = function(){
alert(typeof $scope.selectedNum); //alerts string, need this to be a number
}
});
I'm new to angular - coming from jQuery I'm used to explicitly invoking Number($('#mySelect').val()) but in angular the value is bound automatically to the $scope.
My question: is there a way to force $scope.selectedNum to be type number? In my actual project I use the selectedNum to do some calculations. I suppose I can use Number(..) or parseInt(..) in various places but I'm thinking that might get a little repetitive and messy.