@angular/core#INJECTOR TypeScript Examples
The following examples show how to use
@angular/core#INJECTOR.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: component-creator.service.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 6 votes |
constructor(
@Inject(DOCUMENT)
private readonly document: Document,
private readonly rendererFactory: RendererFactory2,
private readonly appRef: ApplicationRef,
private readonly componentFactoryResolver: ComponentFactoryResolver,
private readonly injector: Injector,
private ngZone: NgZone
) {
this.renderer = rendererFactory.createRenderer(null, null);
}
Example #2
Source File: settings.component.ts From rubic-app with GNU General Public License v3.0 | 6 votes |
constructor(
private readonly headerStore: HeaderStore,
private readonly themeService: ThemeService,
private readonly destroy$: TuiDestroyService,
@Inject(Injector) public readonly injector: Injector
) {
this.defaultComponent = {
titleKey: 'Settings',
component: new PolymorpheusComponent(SettingsListComponent)
};
this.currentComponent$ = new BehaviorSubject(this.defaultComponent);
this.isMobile$ = this.headerStore.getMobileDisplayStatus();
}
Example #3
Source File: outletComponent.c.ts From ngx-dynamic-hooks with MIT License | 6 votes |
// Lifecycle methods
// ----------------------------------------------------------------------
constructor(
private hostElement: ElementRef,
private outletService: OutletService,
private componentUpdater: ComponentUpdater,
private platform: PlatformService,
private injector: Injector
) {}
Example #4
Source File: browser-outlet.component.ts From scion-microfrontend-platform with Eclipse Public License 2.0 | 6 votes |
constructor(host: ElementRef<HTMLElement>,
formBuilder: FormBuilder,
private _activatedRoute: ActivatedRoute,
private _overlay: Overlay,
private _injector: Injector) {
this.form = formBuilder.group({
[URL]: new FormControl('', Validators.required),
});
this.appEntryPoints = this.readAppEntryPoints();
}
Example #5
Source File: app.injector.ts From App with MIT License | 6 votes |
/**
* Helper to set the exported {@link AppInjector}, needed as ES6 modules export
* immutable bindings (see http://2ality.com/2015/07/es6-module-exports.html) for
* which trying to make changes after using `import {AppInjector}` would throw:
* "TS2539: Cannot assign to 'AppInjector' because it is not a variable".
*/
export function setAppInjector(injector: Injector): void {
if (AppInjector) {
return undefined;
}
AppInjector = injector;
}
Example #6
Source File: dialog.service.ts From alauda-ui with MIT License | 6 votes |
private createInjector<T>(
config: DialogConfig,
dialogRef: DialogRef<T>,
dialogIns: DialogComponent,
): Injector {
const userInjector = config?.viewContainerRef?.injector;
return Injector.create({
providers: [
{
provide: DialogRef,
useValue: dialogRef,
},
{
provide: DIALOG_DATA,
useValue: config.data || dialogIns,
},
],
parent: userInjector || this.injector,
});
}
Example #7
Source File: webcomponents.module.ts From geonetwork-ui with GNU General Public License v2.0 | 6 votes |
constructor(private injector: Injector) {
CUSTOM_ELEMENTS.forEach((ceDefinition) => {
const angularComponent = ceDefinition[0]
const ceTagName = ceDefinition[1]
const customElement = createCustomElement(angularComponent, {
injector,
})
if (!customElements.get(ceTagName)) {
customElements.define(ceTagName, customElement)
}
})
}
Example #8
Source File: golden-layout-component.service.ts From golden-layout-ng-app with MIT License | 6 votes |
createComponent(componentTypeJsonValue: JsonValue, container: ComponentContainer) {
const componentType = this._componentTypeMap.get(componentTypeJsonValue as string);
if (componentType === undefined) {
throw new Error('Unknown component type')
} else {
const provider: StaticProvider = { provide: BaseComponentDirective.GoldenLayoutContainerInjectionToken, useValue: container };
const injector = Injector.create({
providers: [provider]
});
const componentFactoryRef = this.componentFactoryResolver.resolveComponentFactory<BaseComponentDirective>(componentType);
return componentFactoryRef.create(injector);
}
}
Example #9
Source File: dialog.service.ts From mysteryofthreebots with Apache License 2.0 | 6 votes |
constructor(
rendererFactory: RendererFactory2,
private readonly resolver: ComponentFactoryResolver,
private readonly injector: Injector,
private readonly appRef: ApplicationRef,
@Inject(DOCUMENT) private readonly document: HTMLDocument
) {
this.renderer = rendererFactory.createRenderer(null, null);
this.handleCloseDialog = this.handleCloseDialog.bind(this);
}
Example #10
Source File: tour-anchor.directive.ts From ngx-ui-tour with MIT License | 6 votes |
constructor(
private componentFactoryResolver: ComponentFactoryResolver,
private injector: Injector,
private viewContainer: ViewContainerRef,
private element: ElementRef,
private tourService: NgxmTourService,
private tourStepTemplate: TourStepTemplateService,
private tourBackdrop: TourBackdropService
) {
this.opener = this.viewContainer.createComponent(
this.componentFactoryResolver.resolveComponentFactory(
TourAnchorOpenerComponent
)
).instance;
}
Example #11
Source File: app-loader.service.ts From angular-dream-stack with MIT License | 6 votes |
createParentInjector(injector: Injector) {
return Injector.create({
providers: [
{
provide: Router,
useValue: null,
},
{
provide: Store,
useValue: null,
},
{
provide: EffectsRunner,
useValue: null,
},
{
provide: PlatformLocation,
useClass: AppPlatformLocation,
deps: [],
},
],
parent: injector,
});
}
Example #12
Source File: content-list.component.ts From litefy with MIT License | 6 votes |
constructor(
private playerService: SpotifyPlayerService,
private service: ServiceBase,
private router: Router,
private youtubeService: YoutubeService,
private youtubePlayerService: YoutubePlayerService,
private userService: UserService,
public translateService: TranslateService,
injector: Injector
) {
super(injector);
}
Example #13
Source File: example.component.ts From open-source with MIT License | 6 votes |
constructor(
public readonly injector: Injector,
private readonly cdr: ChangeDetectorRef,
private readonly snackbar: MatSnackBar,
private readonly clipboard: Clipboard,
private readonly route: ActivatedRoute,
private readonly content: ContentService,
private readonly i18n: I18nService,
) {}
Example #14
Source File: np-dialog.service.ts From np-ui-lib with MIT License | 6 votes |
open(
content: string | TemplateRef<any>,
config: NpDialogConfig,
data: any
): NpDialogRef {
const positionStrategy = this.overlayPositionBuilder
.global()
.centerHorizontally()
.centerVertically();
if (!config) {
config = new NpDialogConfig({});
}
const overlayConfig = new OverlayConfig({
positionStrategy,
hasBackdrop: config.hasBackDrop,
backdropClass: config.backDropClass || "np-dialog-backdrop",
scrollStrategy: this.overlay.scrollStrategies.block(),
panelClass: "np-dialog-overlay",
});
const overlayRef = this.overlay.create(overlayConfig);
const myOverlayRef = new NpDialogRef(overlayRef, content, config, data);
const injector = Injector.create({
parent: this.injector,
providers: [{ provide: NpDialogRef, useValue: myOverlayRef }],
});
overlayRef.attach(new ComponentPortal(NpDialogContainerComponent, null, injector));
return myOverlayRef;
}
Example #15
Source File: chat-bottom-bar.component.ts From onchat-web with Apache License 2.0 | 6 votes |
constructor(
public globalData: GlobalData,
public elementRef: ElementRef<HTMLElement>,
private socket: Socket,
private overlay: Overlay,
private renderer: Renderer2,
private platform: Platform,
private injector: Injector,
private destroyer: Destroyer,
) { }
Example #16
Source File: add-torrent-dialog-component.ts From storm with MIT License | 6 votes |
constructor(injector: Injector) {
this.api = injector.get(ApiService) as ApiService;
this.ref = injector.get(DynamicDialogRef) as DynamicDialogRef;
this.data = (injector.get(DynamicDialogConfig) as DynamicDialogConfig).data || {};
this.config = {
MaxDownloadSpeed: -1,
MaxUploadSpeed: -1,
};
}
Example #17
Source File: directive-superclass.spec.ts From s-libs with MIT License | 6 votes |
constructor(
@Inject('color$') color$: Observable<string>,
injector: Injector,
) {
super(injector);
this.bindToInstance(
'color',
combineLatest([
this.getInput$('prefix'),
this.getInput$('prefix2'),
color$,
]).pipe(map((parts) => parts.filter((p) => p).join(''))),
);
}
Example #18
Source File: load-component.service.ts From sba-angular with MIT License | 6 votes |
/**
* Dynamically load a component from its type. The component's inputs and outputs will be initialized
* by calling {@link #bindComponent}.
*
* @param options The options containing the component to load and its inputs and outputs
* @param viewContainerRef Specifies where the loaded component should be attached. If not specified then the
* loaded component is inserted before the application component
* @param injector Overrides the injector to use as the parent for the component. By default this will be
* the injector held on the `viewContainerRef`
*/
loadComponent<T>(options: LoadComponentOptions, viewContainerRef?: ViewContainerRef, injector?: Injector): LoadedComponent {
let componentRef: ComponentRef<T>;
let factory = this.factories.get(options.component);
if (!factory) {
factory = this.componentFactoryResolver.resolveComponentFactory(options.component);
}
if (!viewContainerRef) {
const appElement: Element = this.applicationRef.components[0].location.nativeElement;
const injector1 = this.applicationRef.components[0].injector;
componentRef = factory.create(injector1, [[appElement]]);
this.applicationRef.attachView(componentRef.hostView);
if (appElement.parentElement) {
appElement.parentElement.insertBefore(componentRef.location.nativeElement, appElement.nextSibling);
}
}
else {
if (!injector) {
injector = viewContainerRef.injector;
}
const index = !Utils.isEmpty(options.index) ? options.index : undefined;
componentRef = viewContainerRef.createComponent(factory, index, injector, []);
}
const loadedComponent: LoadedComponent = {
componentRef
};
this._bindComponent(options, loadedComponent, true);
loadedComponent.componentRef.changeDetectorRef.detectChanges();
return loadedComponent;
}
Example #19
Source File: ngx-mat-timepicker-time-locale.token.spec.ts From ngx-mat-timepicker with MIT License | 6 votes |
describe("TimeLocaleToken", () => {
it("should return provided locale", () => {
const locale = "en-GB";
const injector = Injector.create({providers: [{provide: NGX_MAT_TIMEPICKER_LOCALE, useValue: locale}]});
const actual = injector.get(NGX_MAT_TIMEPICKER_LOCALE);
expect(actual).toBe(locale);
});
});
Example #20
Source File: info.component.ts From dev-manager-desktop with Apache License 2.0 | 6 votes |
renewScript(): void {
this.modalService.open(RenewScriptComponent, {
size: 'lg',
// scrollable: true,
injector: Injector.create({
providers: [{provide: 'device', useValue: this.device}]
})
});
}
Example #21
Source File: page.service.ts From angular-miniprogram with MIT License | 6 votes |
register() {
this.app.__ngStartPage = <M, C>(
module: Type<M>,
component: Type<C>,
miniProgramComponentInstance: MiniProgramComponentInstance
) => {
return this.ngZone.run(() => {
const injector = Injector.create({
providers: [
{ provide: PAGE_TOKEN, useValue: miniProgramComponentInstance },
],
parent: this.injector,
});
const ngModuleRef = createNgModuleRef(module, injector);
const componentFactory =
ngModuleRef.componentFactoryResolver.resolveComponentFactory(
component
);
const componentRef = componentFactory.create(injector);
this.applicationRef.attachView(componentRef.hostView);
return { componentRef, ngModuleRef };
});
};
}
Example #22
Source File: modal-container.component.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 5 votes |
constructor(
private readonly renderer2: Renderer2,
private readonly el: ElementRef<ModalContainerComponent>,
private readonly componentFactoryResolver: ComponentFactoryResolver,
private readonly injector: Injector,
) { }
Example #23
Source File: errors.service.ts From rubic-app with GNU General Public License v3.0 | 5 votes |
constructor(
private readonly notificationsService: NotificationsService,
@Inject(Injector) private injector: Injector,
private translateService: TranslateService
) {}
Example #24
Source File: global-error-handler.service.ts From ng-conf-2020-workshop with MIT License | 5 votes |
constructor(private injector: Injector, private zone: NgZone) { }
Example #25
Source File: panel-factory.service.ts From ngx-colors with MIT License | 5 votes |
constructor(
private resolver: ComponentFactoryResolver,
private applicationRef: ApplicationRef,
private injector: Injector
) {}
Example #26
Source File: parserEntryResolver.ts From ngx-dynamic-hooks with MIT License | 5 votes |
/**
* Takes a list of HookParserEntries and transforms them into a list of loaded HookParsers
*
* @param parserEntries - The list of HookParserEntries to process
* @param injector - The injector to use for resolving parsers
* @param blacklist - (optional) Which parsers to blacklist by name
* @param whitelist - (optional) Which parsers to whitelist by name
*/
resolve(parserEntries: Array<HookParserEntry>, injector: Injector, blacklist?: Array<string>, whitelist?: Array<string>): Array<HookParser> {
// Load all requested parsers
const parsers: Array<HookParser> = [];
for (const parser of parserEntries) {
const resolvedParser = this.resolveEntry(parser, injector);
if (resolvedParser) {
parsers.push(resolvedParser);
}
}
// Check parser functions
const validParsers = this.validateParserFunctions(parsers);
// Check parser names
this.checkParserNames(validParsers);
// If no need to filter, return resolved parsers
if (!blacklist && !whitelist) {
return validParsers;
}
// Check black/whitelist
this.checkBlackAndWhitelist(validParsers, blacklist, whitelist);
// Filter parsers
const filteredParsers = [];
for (const validParser of validParsers) {
if (validParser.hasOwnProperty('name') && typeof validParser.name === 'string') {
if (blacklist && blacklist.includes(validParser.name)) {
continue;
}
if (whitelist && !whitelist.includes(validParser.name)) {
continue;
}
}
filteredParsers.push(validParser);
}
return filteredParsers;
}
Example #27
Source File: error.service.ts From leapp with Mozilla Public License 2.0 | 5 votes |
// Don't use regular dependency injection but instead use injector!
constructor(private injector: Injector) {}
Example #28
Source File: global-injector.module.ts From barista with Apache License 2.0 | 5 votes |
constructor(private injector: Injector) {
AppInjector = this.injector;
}
Example #29
Source File: router-outlet.component.ts From scion-microfrontend-platform with Eclipse Public License 2.0 | 5 votes |
constructor(formBuilder: FormBuilder,
private _overlay: Overlay,
private _injector: Injector) {
this.form = formBuilder.group({
[OUTLET_NAME]: new FormControl(''),
});
}