Seiten

Angular (2) module and ES6 modules

Diving deeper into Angular (2) during the last weeks I came to attention about the difference of the Angular2 module (NgModule) concept in comparison with the ES6 module concept:


ES6 modules export JavaScript elements per file. This is a low level module concept on basis of the programming language without any semantic meaning.

Angular modules define modules in the semantics of Angular as a framework for building single page web/mobile apps. An Angular module defines which Angular specific elements
  • belong together, 
  • are exported and 
  • are imported.
Further Angular specific elements are Components, Directives, Filters and Services. Such semantic could not be achieved with the use of ES6 modules. The Angular module concept is completly disjoint from ES6 modules as Angular does not make any requirements about the organization of Angular2 elements in files (although this topic is covered in the Angular2 styleguide which should be take into account in any case).

Some may think that the above comparsion is superfluous because the difference is quite clear, but I found some so called 'professional' articles that lack clear statements, like the following I found describing Angular modules in short:

"Modules are blocks of code that do a certain type of task. A module exports some value in the main code, such as class. The first and the most common module that you will study is the one that exports Component Class."

This explains ES6 modules that are part of the language but not the Angular module concept in any way.

Update, 03/01/2017:
Here are some sources about the topics:
Javascript and Modules
Angular Modules

Keine Kommentare:

Kommentar veröffentlichen