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



No comments:

Post a Comment