Created
February 22, 2022 15:59
-
-
Save corespider/975ca6aec21c0416c7ffd87c5881d8e4 to your computer and use it in GitHub Desktop.
How many types of modules present in Angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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