Questions about dependency injections in angularJs 1.x

14 views
Skip to first unread message

Rafa

unread,
Oct 31, 2017, 4:55:46 AM10/31/17
to Angular and AngularJS discussion
If in a lot of controllers I inject modules or scopes that I do not use later, Could this affect the overall performance of the development?

For example, sometimes I inject $rootscope in many controllers and  I do not end up using it inside the controller. Same thing happens me with the $timeout.

Is it better to remove this not used injections if they are not used or they are invaluables in terms of performance?

One more doubt,

When we create new variables inside a controllers for use as references to internal data arrays or references to objects and we wanted  them only inside the controller

What is best to use whenever possible?

var newArray;

or

$scope.newArray

What is the diference, ¿both of them are going to be deleted when controller scope is detroyed, aren't them?

Thank you

Sander Elias

unread,
Nov 1, 2017, 5:34:15 AM11/1/17
to Angular and AngularJS discussion
Hi Rafa,

If you are concerned about performance, don't use $scope at all. You don't need it, and you will run into edge-cases, and other unpleasant stuff. read through the style-guide for more details.

The DI, has no real bearing on performance. Doing things that go into the grain of the framework does. Again, have a look at the style-guide. it explains most of this.

Regards
Sander
Reply all
Reply to author
Forward
0 new messages