DEV Community

Discussion on: Angular Modules Best Practices 2021

Collapse
 
jwp profile image
John Peters

Just wondering your thoughts on ECMA modules and if Angular should deprecate their system?

Collapse
 
xroal profile image
Roman Stejskal

Angular needs NgModules to provide context to template compilation.

In short, when the Angular compiler encounters a component, directive or a pipe, it needs a class to associate to it, and it looks for this class in the same module where your component is declared. If it wasn't for modules, Angular would have to search all of your files, and potentially even pick the incorrect class.

That being said, the Angular team is looking into possibilities to get rid of NgModules.

Collapse
 
jwp profile image
John Peters

Yes I think the ECMA modul system is far superior to NgModule and that Angular complier already has the directives need to go full blown ECMA modules.

One of the reasons React is so popular is ease of use. Until Angular understands that they will continue to slide in popularity.