3

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?

Ph0en1x
  • 9,943
  • 8
  • 48
  • 97

1 Answers1

1

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.

pkozlowski.opensource
  • 117,202
  • 60
  • 326
  • 286