What is the difference between component and module in angular

1.0K    Asked by KabirSingh in Python , Asked on Jan 12, 2020
Answered by Arun Singh

Components control views (html). They also communicate with other components and services to bring functionality to your app.

Modules consist of one or more components. They do not control any html. Your modules declare which components can be used by components belonging to other modules, which classes will be injected by the dependency injector and which component gets bootstrapped. Modules allow you to manage our components to bring modularity to our app.

Let’s us understand by using an example

Consider your angular Application as a Building. A Building can have N number of Apartments in it. An Apartment is considered as a Module. An Apartment can have N number of rooms which correspond to the building blocks of an Angular application named Components.

Now each Apartment (Module) will have Rooms (Components), Lifts (Services) to enable larger movement in and out the apartments, Wires (Pipes) to move information around and make it useful in the apartments.

You will also have places like a swimming pool, tennis court which are being shared by all building residents. So these can be considered as components inside Shared Module.



Your Answer

Interviews

Parent Categories