Skip to content

Instantly share code, notes, and snippets.

@debugmodedotnet
Created August 10, 2022 11:14
Show Gist options
  • Save debugmodedotnet/d25e4d71f258ab6cb3558489fa8e11c8 to your computer and use it in GitHub Desktop.
Save debugmodedotnet/d25e4d71f258ab6cb3558489fa8e11c8 to your computer and use it in GitHub Desktop.
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