Home >Web Front-end >JS Tutorial >Detailed explanation of NgModule (module) in Angular

Detailed explanation of NgModule (module) in Angular

青灯夜游
青灯夜游forward
2021-04-16 17:54:422085browse

This article will take you to learn more about NgModule (module) in Angular. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

Detailed explanation of NgModule (module) in Angular

Angular module (NgModule)

  • Angular applications are modular and have their own modular system called NgModule . An NgModule is a container used to store some cohesive code blocks that focus on a certain application area, a certain workflow, or a set of closely related functions. It can contain some components, service providers or other code files, the scope of which is defined by the NgModule that contains them. It can also import some functions exported by other modules, and export some specified functions for use by other NgModules.
  • A module is also a TypeScript class with the @NgModule decorator.

Related tutorial recommendations: "angular tutorial"

NgModule metadata

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import {HttpClient, HttpClientModule} from '@angular/common/http';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpClientModule,
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
  • declarations

#Declaring something in a module can only declare components, instructions and pipes.

  • imports

The import table declares some modules that the application depends on to run.

  • providers

Declares which services are provided in the module, only services can be declared.

  • bootstrap

Declares what the main component of the module is. Only the root module should set this bootstrap attribute.

For more programming-related knowledge, please visit: Programming Teaching! !

The above is the detailed content of Detailed explanation of NgModule (module) in Angular. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete