Skip to content

Commit

Permalink
feat(workbench/popup): allow registering providers for dependency inj…
Browse files Browse the repository at this point in the history
…ection

Unlike providers that are registered via a separate injector, passed providers are registered in the same injector as the popup handle itself, allowing for dependency injection of the popup handle in providers.
danielwiehl authored and Marcarrian committed Apr 13, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 54b9eb4 commit c2cec23
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion projects/scion/workbench/src/lib/popup/popup.config.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
* SPDX-License-Identifier: EPL-2.0
*/

import { ComponentFactoryResolver, ElementRef, Injector, Type, ViewContainerRef } from '@angular/core';
import { ComponentFactoryResolver, ElementRef, Injector, StaticProvider, Type, ViewContainerRef } from '@angular/core';
import { Observable } from 'rxjs';

/**
@@ -56,6 +56,11 @@ export abstract class PopupConfig {
* ```
*/
injector?: Injector;
/**
* Specifies providers to be registered with the popup injector. Unlike providers that are registered via a separate {@link injector},
* passed providers are registered in the same injector as the popup handle itself, allowing for dependency injection of the popup handle.
*/
providers?: StaticProvider[];
/**
* Sets the component's attachment point in Angular's logical component tree (not the DOM tree used for rendering), effecting when
* Angular checks the component for changes during a change detection cycle. If not set, inserts the component at the top level
1 change: 1 addition & 0 deletions projects/scion/workbench/src/lib/popup/popup.service.ts
Original file line number Diff line number Diff line change
@@ -115,6 +115,7 @@ export class PopupService {
providers: [
{provide: PopupConfig, useValue: config},
{provide: Popup, useValue: popupHandle},
...[config.componentConstructOptions?.providers || []],
],
}));
const componentRef = overlayRef.attach(popupPortal);

0 comments on commit c2cec23

Please sign in to comment.