ANGULAR INTERVIEW QUESTION: Can you explain how works the @NgModule decorator?
First, let's define what is an Angular Module:
๐๐ง ๐๐ง๐ ๐ฎ๐ฅ๐๐ซ ๐ฆ๐จ๐๐ฎ๐ฅ๐ ๐ ๐ซ๐จ๐ฎ๐ฉ๐ฌ ๐๐ข๐๐๐๐ซ๐๐ง๐ญ ๐ฉ๐ซ๐จ๐ฃ๐๐๐ญ๐ฌ ๐ข๐ญ๐๐ฆ๐ฌ ๐ฅ๐ข๐ค๐ ๐๐จ๐ฆ๐ฉ๐จ๐ง๐๐ง๐ญ๐ฌ, ๐๐ข๐ซ๐๐๐ญ๐ข๐ฏ๐๐ฌ, ๐ฌ๐๐ซ๐ฏ๐ข๐๐๐ฌ, ๐ฉ๐ข๐ฉ๐๐ฌ ๐ญ๐จ ๐๐ฎ๐ฅ๐ฅ๐๐ข๐ฅ๐ฅ ๐ ๐ฌ๐ฉ๐๐๐ข๐๐ข๐ ๐ฉ๐ซ๐จ๐ฃ๐๐๐ญ ๐๐๐๐ญ๐ฎ๐ซ๐.
Technically, a module is a class bound to a decorator @NgModule, allowing to describe how the app items box ๐ฆ between themselves.
Below the code of a module class:
In "๐๐๐๐๐๐ก๐ ": we put all the modules required by this module.
In "๐๐ฅ๐๐๐๐ก๐ ", we expose the items of this module so that other modules can import them.
In "๐๐๐๐๐๐๐๐ก๐๐๐๐ ", we list all the elements of the module, you need to declare your items so that Angular recognizes it.
In "๐๐๐๐ฃ๐๐๐๐๐ ", we put the service to inject for that module.
In "๐๐๐๐ก๐ ๐ก๐๐๐", we put the component that is first loaded by the app; this property is only used for the "๐๐๐๐ก" module "๐ด๐๐๐๐๐๐ข๐๐.๐ก๐ "