A function in my AngularJS controller are invoked multiple times (20+) for each route change. How can I avoid this?
I've made a simple example: http://jsfiddle.net/r6rv078t/3/
Why is this happening, and what are the other digest related pitfalls that an AngularJS developer should be aware of?
var myController = function ($scope, $location) {
var _count = 0;
$scope.locChangeCounter = {
count: function (viewLocation) {
console.log(' $location ... ' + $location);
_count++;
return _count;
}
};
console.log(' just with in ctrl ... ' + $location);
};