Created
August 10, 2022 11:14
-
-
Save debugmodedotnet/d25e4d71f258ab6cb3558489fa8e11c8 to your computer and use it in GitHub Desktop.
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
import { inject, InjectOptions, Type } from "@angular/core"; | |
export class RootInjectorGuard { | |
option: InjectOptions = { | |
skipSelf: true, | |
optional: true | |
}; | |
constructor(type: Type<any>) { | |
console.log(type.name); | |
const parent = inject(type, this.option); | |
if (parent) { | |
throw Error(`[${type.name}]: Can not create more than one instance`); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment