re: Dependency Injection in JavaScript 101 VIEW POST

re: Incredible! But one doubt: when you'll use ".register", you've to specify first the label and then the class, right?

Correct. In the simple DI example you pass a label (string), then an array that should have the function constructor, factory, or instance as the last element.


Great! And in this case: "$jsInject.register("engine", ["pistons", Engine]);", you have to pass the "pistons" in the array too because "Engine" receives "pistons" as a parameter, right? And then the last element would be "Engine" cuz is the "current class".

You got it! The important part of the illustration is that "pistons" is just a label, not an implementation, so you have flexibility to define it however you see fit elsewhere.

Oh, I get it! Then I'll use this label on "$jsInject.get()". Amazing!! Thanks ;)

code of conduct - report abuse