When you develop Single Page Application (SPA) with Angular framework it is very important to know the difference between component and module.
In this article I am going to discuss this in detail
Components
You can create the component with following command
1 |
ng generate component product |
The component is the basic building block in Angular application. You can have more than one component when you develop application. Component can control the view (html) in your app and it can communicate with other component and services.
So, when you create a component (for example product), it will create four files
product.component.css
product.component.html
product.component.spec.ts
product.component.ts
Modules
You can create the module with following command
1 |
ng g module products --routing |
Module consists of one or more components. You are not going to control HTML with module. So what module does is , building blocks like component, directives, services etc put together
Module is used to grouped set of functionalities