Skip to content

Instantly share code, notes, and snippets.

@corespider
Created February 22, 2022 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corespider/975ca6aec21c0416c7ffd87c5881d8e4 to your computer and use it in GitHub Desktop.
Save corespider/975ca6aec21c0416c7ffd87c5881d8e4 to your computer and use it in GitHub Desktop.
How many types of modules present in Angular
// core module example
import { NgModule, Optional, SkipSelf } from '@angular/core';
import { ApiService } from './services/api.service';
@NgModule({
providers: [ ApiService ]
})
export class CoreModule {
// do not allow to be used more than ONCE!!!
constructor(@Optional() @SkipSelf() parent: CoreModule) {
if (parent) {
throw new Error(
'Import CoreModule in the root module only!!!'
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment