Skip to content Skip to sidebar Skip to footer

View Is Getting Initialized Again And Again

I'm building a dashboard similar to this one Admin Dashboard Theme I'm implementing the Right Side SideBar as show in the screenshot My App code structure is something like: index

Solution 1:

You need to familiarize yourself with the concept of a digest loop in Angular.

In short, every time a digest loop runs, all expressions, e.g. {{name}} or ng-show="isActive && isEnabled", that are being "$watched" by Angular are evaluated (sometimes more than once). This means that if you are invoking a function inside an expression:

<divng-show="isShown()">
$scope.isShown = function(){
   console.log("expect to see this text a lot of times");
   returntrue;
};

the function will be executed on every digest loop.

A digest loop runs any time that something in Angular calls $scope.$digest, which by default happens on things like ng-click or ng-change or $http.then, etc..

Post a Comment for "View Is Getting Initialized Again And Again"