A call stack is a chain of calls made by a specific function, for example, what you can see inside the console when a javascript error occurs. for instance
at Scope.$scope.openRightMenu (site/header.ctr.js:19:12) at Parser.functionCall (site/bower_components/angular/angular.js:10567:21) at site/bower_components/angular-touch/angular-touch.js:438:9 at Scope.$get.Scope.$eval (site/bower_components/angular/angular.js:12412:28) at Scope.$get.Scope.$apply (site/bower_components/angular/angular.js:12510:23) at HTMLDivElement.<anonymous> (site/bower_components/angular-touch/angular-touch.js:437:13)
This is a call stack. Now the $ apply () function should be called when the entire function loop is complete, so it says that it should be at the highest level of the call stack. Because you need to be sure that every process is executed in order to make $ apply () safe, also because, as you know, you cannot do 2 digest cycles in the same $ area at once.
So if you have
func a() -> calling -> func b() //setting $scope elaborated data func b() -> calling -> func c() //elaborating data func c() -> calling -> func d() //getting data
Your call to $ apply () should be inside func a (), being the very highest level of the call stack.
Bolza source share