In the previous post, we saw what Angular2 is all about. We discussed the selection of editors & programming languages for our application. We also discussed how we can build up our application architecture and install the required dependencies, using npm.
In this post, we’ll try to explore the starter files, which we downloaded and understand them thoroughly. If you open your app folder inside it, we’ll find 3 files namely
- modules.ts- This is our application root module. Each & every application will have a root module.
- component.ts- This is our application root component. Each & every application will have a root component.
- ts- This is our application bootstrapper. It will bootstrap our application onto the browser.
What is an Angular2 Module Or @NgModule({})?
Angular2 is fully modularized. It has different modules such as “angular2/core”, “angular2/routing”, “angular2/http” etc. These modules are called Angular modules or @NgModules. You’ll find app.modules.ts in our application as a class decorated with @NgModule({}) decorator. @NgModule({}) helps us in modularizing our code. Each application will have a root module. However, in your application, you can always have sub modules too, but always remember to register your sub modules with the main module. How to register a module with the main module? We’ll discuss it later in this series. The default naming convention for main module name is “app.module.ts”. The contents of it are given below.
- /** Importing the angular modules from namespace */
- import {
- NgModule
- } from '@angular/core';
- import {
- BrowserModule
- } from '@angular/platform-browser';
- /** Importing the AppComponent from the application's app folder */
- import {
- AppComponent
- } from './app.component';
- @NgModule({
- imports: [BrowserModule], //other modules whose exported classes are needed by component templates declared in this module.
- declarations: [AppComponent], // the view classes that belong to this module. Angular has three kinds of view classes: components, directives, and pipes.
- bootstrap: [AppComponent] //the main application view, called the root component, that hosts all other app views. Only the root module should set this bootstrap property.
- })
- export class AppModule {}
For more information on @NgModules, follow this link.
What is an Angular2 Component?
In Angular2, everything is a component. They are the building blocks of our application. Angular2 component consists of
- Typescript class, which has methods (used for binding events to HTML elements) & properties (used for binding properties to HTML elements).
- An HTML markup for view (UI).
- An Angular metadata (instructs Angular about how to process the class).






Manav PandyaPosted Jan 8, 2017, 1:04 AM
Yeh thanks for sharing sir @vishal