4

I've always been a supporter of requirejs and AMD, but since I started to learn AngularJS I feel uncomfortable to combine the two technologies together.

I know it is actually possible to use requirejs to manage and load dependencies in an angularjs application, and the same developers call the two products "orthogonal", but how much value can it add?

The first argument it comes to my mind is dependency injection, it actually decouples the dependencies between modules, that translated it means I don't need to keep track of the dependencies nor of the script loading order (at least most of the time). On top of that it seems AMD can even go against the principles behind the DI, because it requires to hardcode the dependency somewhere into the scripts...

So would it be wise to say that using AMD in an angulajs application would add only additional complexity without bringing any major advantage?

Mario
  • 3,223
  • 3
  • 19
  • 21

1 Answers1

3

I don't think of AMD as dependency injection. It's a module loader. The roles are different. RequireJS loads files for you: Angular doesn't do that at all.

For example, I don't list "underscore" in my list of angular dependencies. If I need it in an service, I let RequireJS load it for me. Angular does inject all the application code though.

Sean Clark Hess
  • 15,859
  • 12
  • 52
  • 100
  • The major advantage of dependency injection is that you decouple the dependency from its implementation. AMD goes exactly against this, IMHO, because you have to specify in the "require" what is the implementation of the dependency... – Mario Oct 23 '12 at 22:53