I have some troubles with select and ng-change: I’m trying to calculate a value with couple of text boxes and two selects.
For some reason Controller gets always default value from the selects even while View seems to have correct user selected value.
This is my View:
<ion-view title="Nitrox calculator">
<ion-content class="padding">
<select ng-model="foo" ng-change="changedValue()"
ng-options="foo as foo.name for foo in blisterPackTemplates">
</select>
{{itemListFoo}}
<br></br>
<select ng-model="bar" ng-change="changedValue()"
ng-options="bar as bar.name for bar in blisterPackTemplates">
</select>
{{itemListBar}}
</ion-content>
</ion-view>
And the Controller:
angular.module('starter.controllers', [])
.controller('Calculator', function($scope) {
$scope.itemListFoo=[];
$scope.itemListBar=[];
$scope.blisterPackTemplates=[{id:0,name:"--Select--"},{id:1,name:"a"},{id:2,name:"b"},{id:3,name:"c"}];
$scope.foo=$scope.blisterPackTemplates[0];
$scope.bar=$scope.blisterPackTemplates[0];
$scope.changedValue=function(){
var d2 = $scope.bar;
var d1 = $scope.foo;
$scope.itemListBar.push('d2: '+d2.name);
$scope.itemListFoo.push('d1: '+d1.name);
}
});
Function changedValue() has always values of $scope.foo and $scope.bar “–Select–”.
But in http://jsfiddle.net/leppto/6o3fk751/ this works as expected.