Introduction
In this article, we are going to discuss Angular components. This article is for beginners who are planning to learn and implement Angular. In the first part, we will have a brief introduction of Angular Components. After that, we will demonstrate the configuration steps to configure components in Angular.
Components
The main responsibility of the component is to deal with a View of the application and a logic on the page. The component has enough information on how to render itself and fetches data from required services. For example: EmployeeComponent, this will list out the Employee related information in a View or page. To get more information on Components, you can refer to my previous article, An Overview of Angular.
Component Oriented Application
Angular 2 application has a set of components. Every application has a root component which is the container for all the other components, we define a component for a UI element, View, and route. We need to break the application into a set of components. You can break it up as much as you can. Nothing wrong in that, in fact, it will bring the aspects of the application such as reusability, maintenance and testing. Let's see how we can define the component in Angular.
Configuration
Step 1 Package Installation
Define the list of required packages in package.json to build Angular 2 application. Please refer to the attached source-code to understand the packages and dependencies needed to build Angular 2 application. After that, launch the node package manager (npm) and type -
Step 2 Root Module Creation
I am not going into the details of the module here. If you need basic information about the Module, please refer to my recent article ‘Overview of Angular – Part One’ where you will find the details of it. Modules are of two types - root module and feature module. If Angular finds NgModule in the source-code, it will treat as root module. Otherwise, it will be treated as feature Module. Root module is the container of all the feature modules. NgModule is a class decorated with @NgModule metadata. This helps to group which child components will come under root module. And it helps to import other modules which are required for the child components, Provides services at the application level that any child component can use.

Have a look at the source-code. This is how we need to create root Module. You can find that I have imported NgModule and Browser Module token from the angular/core, angular/platform-browser. NgModule is used to define imports, declaration, and bootstrapping options. BrowserModule is required for any web based angular application. The bootstrap option tells Angular which component to bootstrap in the application. After that, you need to import the AppComponent and EmployeeComponent. Let’s see in the source-code how it has to be configured.





Join the conversation! Your thoughts help the community grow.