I am pretty new to the world of Angular. What is the difference between CommonModule vs BrowserModule and why one should be preferred over the othe
So, based on the definitions of 'BrowserModule' and 'CommonModule', my suggestion for using them is something like this, You should have the 'BrowserModule' in application module level, 'AppModule':
app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
imports: [
BrowserModule.withServerTransition({ appId: 'ng-cli-universal' })]
having the 'CommonModule' in custom component level, in a SharedModule among the other common modules that you use in the project:
shared.module.ts:
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
imports: [
CommonModule,
FormsModule,
RouterModule
],
exports: [
CommonModule,
FormsModule,
RouterModule]
Then inject this 'SharedModule' into any other custom modules, like this:
login.module.ts:
import { SharedModule } from '../../shared/shared.module';
imports: [
SharedModule]