Modularize Angular #1382

Closed
geddski opened this Issue Sep 19, 2012 · 5 comments

Comments

Projects
None yet
5 participants
Contributor

geddski commented Sep 19, 2012

I noticed on the google group I'm one of many integrating Angular with RequireJS. Are you guys open to the idea of adopting the AMD standard for Angular's internals? Something I love about Angular is it's all about using future web technology today. AMD is today's solution for the upcoming ES6 modules. Adopting RequireJS/AMD would bring the following benefits to projects using Angular:

  1. async loading of dependency files (strong complement to Angular's DI)
  2. combined/compressed/optimized build, including inlined template strings (using RequireJS's r.js)
  3. ability to lazy-load and load-on-demand any controller, templates, services etc.
  4. unused angular modules won't be loaded, like jqlite (if using jQuery) or built in services that aren't used.
  5. gets developers in the module mindset, with a likely straightforward migration path to Harmony modules

Downside is RequireJS adds 15k, but post-build can use require's 1k almond.js shim if necessary. Worth it IMO.

If you're open to this I'm happy to take this on and submit a pull request.

coxx commented Sep 19, 2012

+1
It would be very cool

Owner

mhevery commented Sep 20, 2012

This question comes up often. While the two use the same terminology, they are not the same thing. AMD talks about how to load individual script files into the browser. Angular modules talk about how the application should be assembled. You can only run AMD once on script load, where as you can run angular modules over and over, for example in tests. AMD is higher level it assembles the codebase, angular injector assembles the application.

There is no reason why you can't use AMD with angular today, and I know that some people already have it working in this way.

@mhevery mhevery closed this Sep 20, 2012

Contributor

geddski commented Sep 21, 2012

@mhevery the intent of this issue was for Angular itself to be refactored to take advantage of AMD internally, which would add even more awesome benefits to Angular (see above). Are you open to considering this?

+1
Being able to load resources asynchronously when needed rather than all at once is definitely a good way to go for building none-trivial apps. I like the approach taken here: https://github.com/matys84pl/angularjs-requirejs-lazy-controllers

huntc commented Feb 27, 2013

I have opened a related issue for those who are interested: #2078

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment