angular.module('UniqueNGTest', [
])
.controller('UniqueItemList', ['$scope', function($scope) {
console.log("Unique ItemList controller initialized");
var self = this;
self.count = 4;
self.getItems = function() {
console.log("Unique ItemList.getItems() called");
return [];
}
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="UniqueNGTest">
<div ng-controller="UniqueItemList as lst">
<select ng-options="value for value in [1,2,3,4,5]" ng-model="lst.count"></select>
<div ng-repeat="item in lst.getItems()">foo </div>
</div>
</div>
Looking at the log entries, you notice that the lst.getItems() function is invoked twice during initialization. But why?
Surprisingly, it's also triggered when the value of lst.count is altered, even though it isn't utilized anywhere. While AngularJS may not automatically recognize that lst.count has no impact on lst.getItems(), one might assume otherwise. It would be more intuitive if AngularJS defaulted to assuming independence unless specified with parameters in the function.