Monday, January 23, 2017

Modules in Angular 2

In java script we have problem with namespaces and also with code organization.
Modules provide a solution for this problem.They enable us to decouple our code easier.

Types of modules .
  1. Angular 1 modules
  2. Typescript modules
  3. Angular 2 modules
  4. ES 2015 modules
Lets discuss about angular 2 and ES 2015 modules

ES 2015 Modules

  • ES6 modules are stored in files. There is exactly one module per file and one file per module
  • Before a module can imported, it first needs to be exported as a module
  • Once a module has been exported it can easily be imported from another file

Angular 2 Modules

Angular 2 has its own modules.They are different from Angular 2's implementation of  ES 2015 modules
  • Help organize and application into cohesive blocks of  functionality
  • Every angular application has at least only one angular module by convention called as app module
  • We can have our own feature module and also shared module
         We can load all modules at start or lazy load it later

  • We define an angular module with a class
  • We identify the angular module by attaching @NgModule decorator and passing the metadata in finding the detail of this angular module

Difference between ES modules and angular modules

The main difference is ES files are about code files and angular modules are about our application


  1. I’m so happy to read this. This is the type of manual that needs to be given and not the accidental misinformation that’s at the other blogs. Appreciate your sharing this greatest doc. website designer nyc

  2. I really don’t accept as true with this blog post. Nevertheless, I did looked in Yahoo and I have found out that you’re correct and I was thinking in the improper way. Carry on publishing good quality material like this. nyc web designer

  3. Some times its a pain in the ass to read what people wrote but this website is real user genial ! . best branding agencies san francisco

  4. Sweet website , super layout, really clean and utilize genial . branding agency sf

  5. This is a smart blog. I mean it. You have an excellent knowledge about this topic. Thanks for sharing such a great blogs to us. angular agency