Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a bad practice to have unused dependencies in a angular controller?

I am using angular to write an app. Sometimes I forget to remove unused dependencies from a controller. Will it affect the performance in any way?

like image 451
rgksugan Avatar asked May 08 '14 14:05

rgksugan


People also ask

Which component Cannot be injected as a dependency in AngularJS controller?

Note that you cannot inject "providers" into run blocks. The config method accepts a function, which can be injected with "providers" and "constants" as dependencies. Note that you cannot inject "services" or "values" into configuration.

Why is AngularJS bad?

Problems with people Firstly, since the framework is overcomplicated, not many developers really know it well and it is hard to find such developers is very hard. Secondly, server developers won't understand what is going on front-end and won't be able to read the code at all.

Which components can be injected as a dependency in angular?

Which Component can be Injected as a Dependency In AngularJS? In Angular. JS, dependencies are injected by using an “injectable factory method” or “constructor function”. These components can be injected with “service” and “value” components as dependencies.

What are the advantages of dependency injection in AngularJS?

It relieves a component from locating the dependency and makes dependencies configurable. It also helps in making components reusable, maintainable and testable. AngularJS provides a supreme Dependency Injection mechanism. It provides following core components which can be injected into each other as dependencies.


1 Answers

It will be extra overhead, but it is very very very minor on the AngularJS side[1]. If your injected dependency does a lot in its constructor (say: load for two seconds) and your unused dependency is the first time it is used, it will affect performance (those two seconds). If the dependency would be loaded later in the application anyway, then it's only a matter of losing two seconds here and gaining two seconds there.

[1]: https://github.com/angular/angular.js/blob/736b6c7fed79c8305786bbb86d39dd7af891a162/src/auto/injector.js#L758 is the code in question. It will have your extraneous dependencies, which will be loaded and then cached. If it was already in the cache (or will be later anyway), the performance hit is very minimal. It is, however, visual clutter in your code!

like image 145
Steve Klösters Avatar answered Sep 17 '22 13:09

Steve Klösters