I hope you guys can help me. Check out this short code.
<!DOCTYPE html>
<html ng-app="testApp">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.js"></script>
<script type="text/javascript">
angular.module('testApp', [])
.controller('testController', ['$scope', function ($scope) {
$scope.greetMe = function(){
console.log('I\'ve been called')
return 'Greetings'
};
}]);
</script>
</head>
<body>
<div id="mainWrapper" data-ng-controller="testController">
{{greetMe()}}
</div>
</body>
</html>
also at: http://plnkr.co/edit/K9fgNWcsm5gDvOfB19y6
If you run this in a browser (I tried chrome and firefox), your console shows
(2) I've been called.
I've tried this with angular 1.0.1, 1.2.0 and 1.3.0 rc.0
I discovered this behavior when I added a similar console.log in a method of a controller of a much bigger app that i'm trying to build. I got so shocked, because in my real case that expression is evaluated 6 times and even worse, all properties and all it's children's children are called/executed over and over again as well. In my specific case it seems that also each $http.get() call, triggers a new evaluation round.
Why ? Can I prevent that ?