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 "𝐴𝑝𝑝𝑀𝑜𝑑𝑢𝑙𝑒.𝑡𝑠"