Angular 4 vs. Angular 5

Should you import BrowserModule or CommonModule?

Should you import BrowserModule or CommonModule?
BrowserModule – Most of all browser applications should import BrowserModule from @angular/platform-browser and the BrowserModule provides services that are important to launch and run your browser apps.

Do not import BrowserModule in any other module.

BrowserModule also re-exports CommonModule from @angular/common and CommonModule is used when you want to use directives - NgIf, NgFor and may more.

BrowserModule exports a couple of NgModules like -
exports: [
  CommonModule,
  ApplicationModule
]


And
//AppModule class with the @NgModule decorator
@NgModule({
  declarations: [
    AppComponent,
    LoginComponent,
    MyPipe,
    MyDirective
  ],
  imports: [//DOM rendering, sanitization, and location
    BrowserModule
  ],
  providers: [//service providers
    MySericeService,
    MyModuleModule
  ],
  bootstrap: [AppComponent],  // bootstrapped entry component
  exports: [
    CommonModule,
    ApplicationModule
  ] 
})
export class AppModule {
  //exporting app module
}
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

Should you import BrowserModule or CommonModule? Should you import BrowserModule or CommonModule? Reviewed by Anil Singh on 4:06 AM Rating: (5)
www.code-sample.com/. Powered by Blogger.
^