On Angular 1.3.x I made a select input that calls a function on ng-change. The surrounding has an ng-if statement.
html
<div class="form-group" ng-if="property">
<label for="city-picker">in</label>
<select class='form-control focus input-sm' ng-model="cityIds" ng-options="city.id as city.name for city in cities" ng-change="getMetrics(cityIds)">
<option value="">all</option>
</select>
</div>
controller
app.controller('MainCtrl', function($scope) {
$scope.cities = [{
name: "Amsterdam",
id: 1
},{
name: "paris",
id: 2
}]
$scope.property = true;
$scope.getMetrics = function(cityIds) {
console.log(cityIds);
console.log('$scope.cityIds is undefined: ', $scope.cityIds);
}
});
When I change the select field the ng-change function is called with the correct $scope update, however, the $scope is not updated.
See the following plunker: http://plnkr.co/edit/sQaLts5xyGBjThjdQJwM
When I remove the ng-if statement the $scope is updated correctly by the select input. Could someone explain this behaviour?