Skip to content

Commit

Permalink
feat(window): add component instance property to window ref (#2858)
Browse files Browse the repository at this point in the history
  • Loading branch information
katebatura authored Sep 15, 2021
1 parent a94a867 commit fcf1a08
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class NbOverlayContainerComponent {
this.portalOutlet.detach();
}
this.attachStringContent(null);
this.isAttached = false
this.isAttached = false;
}

protected createChildInjector(cfr: ComponentFactoryResolver): NbPortalInjector {
Expand Down
5 changes: 4 additions & 1 deletion src/framework/theme/components/window/window-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { NbWindowConfig, NbWindowState, NbWindowStateChange } from './window.opt
* The `NbWindowRef` helps to manipulate window after it was created.
* The window can be dismissed by using `close` method of the windowRef.
* You can access rendered component as `componentRef` property of the windowRef.
* Property `contentInstance` contains the instance of the component opened in the window.
*/
export class NbWindowRef {
export class NbWindowRef<T = any> {
componentRef: ComponentRef<NbWindowComponent>;
componentInstance: T;

protected prevStateValue: NbWindowState;
protected stateValue: NbWindowState;
Expand Down Expand Up @@ -83,6 +85,7 @@ export class NbWindowRef {

this._closed = true;
this.componentRef.destroy();
this.componentInstance = null;
this.stateChange$.complete();
this.closed$.next();
this.closed$.complete();
Expand Down
2 changes: 2 additions & 0 deletions src/framework/theme/components/window/window.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ export class NbWindowComponent implements OnInit, AfterViewChecked, OnDestroy {
protected attachComponent() {
const portal = new NbComponentPortal(this.content as Type<any>, null, null, this.cfr);
const ref = this.overlayContainer.attachComponentPortal(portal, this.context);
this.windowRef.componentInstance = ref.instance;

ref.changeDetectorRef.detectChanges();
}
}

0 comments on commit fcf1a08

Please sign in to comment.