Search code examples
angulartypescriptangular-module

Angular import modules on parent of per nested component


Using Angular 12, We have hotel component, and a hotel module -> this imports all the required components and modules for a hotel. Within the hotel component.html, we loop through all the rooms and display a 'hotel-room.component'.

Is it best practice (or performance issues?) to have a child 'hotel-room.module', and import only the required components and modules for a hotel room (baring in mind, there would be multiple hotel rooms on a page ), or to import all the modules and components required at the hotel module (parent) level.


Solution

  • If you are not going to use it anywhere else, there is no need for separate module. Otherwise, it would be very wise to create component module.

    Unless you wanted to lazy-load that particular child component - then module is a way to go.