Take a look at this plunkr: http://plnkr.co/edit/ke4Cjg3gnf2pWUKW1f2b?p=preview.
var app = angular.module('app', []);
app.controller('controller', ['$scope', '$timeout', function($scope, $timeout) {
$scope.items = [
{name:'candy'},
{name:'chocolate'}
];
$scope.choice = null;
$scope.test = function() {
console.log( 'fired' );
}
$timeout( function(){
$scope.choice = $scope.items[0];
}, 2000);
$timeout( function(){
$scope.items = [
{name:'hershey'},
{name:'mint'}
];
}, 5000);
}]);
Moreover
<select
ng-model="choice"
ng-options="item as item.name for item in items"
ng-change="test()">
</select>
I am using a select box with ng-options and an ng-change event. Ng-change documentation states the following:
The ngChange expression is only evaluated when a change in the input value causes a new value to be committed to the model.
It will not be evaluated:
- if the value returned from the $parsers transformation pipeline has not changed
- if the input has continued to be invalid since the model will stay null
- if the model is changed programmatically and not by a change to the input value
It seems that even if I dynamically change the source of ng-options, ng-change fires unless ng-model is null when the changes occur.
Do you think this is intentional or a bug? If it's intentional, how can I modify ng-options without triggering ng-change unless ng-model is first set to null? Otherwise, I may need to report this behavior as unusual.
Thank you!