Here's a more in depth explanation of Angular's DI, RequireJS, and what's coming up in Angular 2.0 and ES6 modules.
Angular DI is not a module loader! It injects objects that have already been loaded using script tags. It does not do lazy-loading. Angular 2.0 will use ES6 import
for module loading. Angular 2.0 will also add a DI layer that runs after the modules load.
I need to go over Java's import
vs. JavaScript's require
/import
and Java singletons to further explain what Angular's DI is doing.
Java's import
allows you to access another package's types without fully qualifying the package name. JavaScript's import
loads a module and creates references to the module's exported objects. These are very different operations. JavaScript's import
is powerful stuff! You have the objects, not just aliases to a package's types.
Singleton is a pattern, not the object itself. In Java you start with a type and have to create an instance. The singleton pattern ensures you have only 1 instance of that t