- Angular 6 - CLI
- Angular 6 - Materials
- Angular 6 - Animations
- Angular 6 - Forms
- Angular 6 - Http Client
- Angular 6 - Http Service
- Angular 6 - Services
- Angular 6 - Routing
- Angular 6 - Pipes
- Angular 6 - Directives
- Angular 6 - Templates
- Angular 6 - Event Binding
- Angular 6 - Data Binding
- Angular 6 - Module
- Angular 6 - Components
- Angular 6 - Project Setup
- Angular 6 - Environment Setup
- Angular 6 - Overview
- Angular 6 - Home
Angular 6 Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Angular 6 - Modules
Module in Angular refers to a place where you can group the components, directives, pipes, and services, which are related to the apppcation.
In case you are developing a website, the header, footer, left, center and the right section become part of a module.
To define module, we can use the NgModule. When you create a new project using the Angular -cp command, the ngmodule is created in the app.module.ts file by default and it looks as follows −
import { BrowserModule } from @angular/platform-browser ; import { NgModule } from @angular/core ; import { AppComponent } from ./app.component ; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
The NgModule needs to be imported as follows −
import { NgModule } from @angular/core ;
The structure for the ngmodule is as shown below −
@NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule ], providers: [], bootstrap: [AppComponent] })
It starts with @NgModule and contains an object which has declarations, import s, providers and bootstrap.
Declaration
It is an array of components created. If any new component gets created, it will be imported first and the reference will be included in declarations as shown below −
declarations: [ AppComponent, NewCmpComponent ]
Import
It is an array of modules required to be used in the apppcation. It can also be used by the components in the Declaration array. For example, right now in the @NgModule we see the Browser Module imported. In case your apppcation needs forms, you can include the module as follows −
import { FormsModule } from @angular/forms ;
The import in the @NgModule will be pke the following −
imports: [ BrowserModule, FormsModule ]
Providers
This will include the services created.
Bootstrap
This includes the main app component for starting the execution.
Advertisements