forRootThe named static functions have their own goals . They are used for peer-to-peer application-level services.
AlertModulethere are no suppliers in it. When you call forRoot, it returns an object of type ModuleWithProviders , which includes with its declarations and providers that are used in . AlertModuleAlertModule
, AlertModule - github
import { CommonModule } from '@angular/common';
import { NgModule, ModuleWithProviders } from '@angular/core';
import { AlertComponent } from './alert.component';
import { AlertConfig } from './alert.config';
@NgModule({
imports: [CommonModule],
declarations: [AlertComponent],
exports: [AlertComponent],
entryComponents: [AlertComponent]
})
export class AlertModule {
static forRoot(): ModuleWithProviders {
return { ngModule: AlertModule, providers: [AlertConfig] };
}
}
, NgModule . , AlertModule, providers . forRoot , AlertModule AlertConfig.