ng-switch-when: Does it recreate new controller each time and remove previous data when selecting different step?

StackOverflow https://stackoverflow.com/questions/19183404

Domanda

I have a single page webapp based on angular.js And seems like I have performance problems. so I have the main controller and view for it which looks like this

<div>
 <div data-ng-switch-when="step1">
  <div data-ng-include="'/partials/step1.html'"></div>
 </div>

 <div data-ng-switch-when="step2">
  <div data-ng-include="'/partials/step2.html'"></div>
 </div>
</div>

for each step I have it's own controller, in our case is step1-ctl and step2-ctl.

So my question is: when I select step2, does angular unbind all elements from step1, remove watches and clean resource? And second question - when I switching between steps, does angular create new controller instance each time, add callbacks, binding, etc?

È stato utile?

Soluzione

Not sure what you mean exactly by "does angular unbind all elements from step1" but what AngularJS is going to do is to destroy a scope created by the ngSwitch directive (plus its children, thus destroying any watches created in the step1) and remove corresponding DOM elements. If you don't use any badly-written directives that could leak resources in the step1.html AngularJS should clean up DOM elements and the corresponding watches.

The answer to your second question is YES.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top