Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit e5ecc62

Browse files
fix(overlay): fix missing context when creating embeddedView
1 parent 7353d20 commit e5ecc62

File tree

6 files changed

+34
-18
lines changed

6 files changed

+34
-18
lines changed

projects/core/src/lib/dialog/dialog.service.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable } from '@angular/core';
1+
import { Injectable, ViewContainerRef } from '@angular/core';
22
import { FivOverlayService, NgContent } from '../overlay/overlay.service';
33
import { FivDialog } from '../dialog/dialog.component';
44

@@ -16,8 +16,16 @@ export interface DialogOptions {
1616
export class FivDialogService {
1717
constructor(private overlay: FivOverlayService) {}
1818

19-
openDialog(content: NgContent<any>, options?: DialogOptions) {
20-
const c = this.overlay.createOverlay<FivDialog>(FivDialog, content);
19+
openDialog(
20+
viewContainerRef: ViewContainerRef,
21+
content: NgContent<any>,
22+
options?: DialogOptions
23+
) {
24+
const c = this.overlay.createOverlay<FivDialog>(
25+
viewContainerRef,
26+
FivDialog,
27+
content
28+
);
2129
c.instance.verticalAlign = options ? options.verticalAlign : 'top';
2230
c.instance.verticalAlign = options ? options.verticalAlign : 'center';
2331
c.instance.backdrop = options ? options.backdrop : true;

projects/core/src/lib/feature-discovery/feature.directive.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
ComponentRef,
1010
TemplateRef,
1111
Output,
12-
EventEmitter
12+
EventEmitter,
13+
ViewContainerRef
1314
} from '@angular/core';
1415
import { FivOverlayService } from '../overlay/overlay.service';
1516
import { FivFeatureDiscovery } from './feature-discovery.component';
@@ -39,6 +40,7 @@ export class FivFeature {
3940

4041
constructor(
4142
@Host() private host: ElementRef,
43+
private viewContainer: ViewContainerRef,
4244
@Host() @Optional() private icon: FivIcon,
4345
private overlay: FivOverlayService,
4446
private platform: Platform
@@ -60,6 +62,7 @@ export class FivFeature {
6062
: this.getBounds(this.host.nativeElement);
6163

6264
this.overlayRef = this.overlay.createOverlay(
65+
this.viewContainer,
6366
FivFeatureDiscovery,
6467
this.fivFeature
6568
);

projects/core/src/lib/overlay/overlay.component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
TemplateRef,
66
Input,
77
Output,
8-
EventEmitter
8+
EventEmitter,
9+
ViewContainerRef
910
} from '@angular/core';
1011
import { FivOverlayContent } from './overlay-content/overlay-content.component';
1112
import { FivOverlayService } from './overlay.service';
@@ -25,11 +26,15 @@ export class FivOverlay {
2526
@Output() afterInit = new EventEmitter();
2627
private _open = false;
2728

28-
constructor(private overlay: FivOverlayService) {}
29+
constructor(
30+
private viewContainer: ViewContainerRef,
31+
private overlay: FivOverlayService
32+
) {}
2933

3034
show(priority?: number, data?: any) {
3135
if (!this.componentRef) {
3236
this.componentRef = this.overlay.createOverlay(
37+
this.viewContainer,
3338
FivOverlayContent,
3439
this.ngContent
3540
);

projects/core/src/lib/overlay/overlay.service.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import {
88
EmbeddedViewRef,
99
ComponentRef,
1010
Renderer2,
11-
RendererFactory2
11+
RendererFactory2,
12+
ViewContainerRef
1213
} from '@angular/core';
13-
export type NgContent<T> = TemplateRef<T> | Type<T> | string;
14+
export type NgContent<T> = TemplateRef<T> | Type<T>;
1415

1516
@Injectable({
1617
providedIn: 'root'
@@ -28,14 +29,14 @@ export class FivOverlayService {
2829
}
2930

3031
createOverlay<T>(
32+
view: ViewContainerRef,
3133
component: Type<T>,
3234
content?: NgContent<T>
3335
): ComponentRef<T> {
34-
const resolvedContent = this.resolveNgContent(content);
36+
const resolvedContent = this.resolveNgContent(view, content);
3537
const componentRef = this.componentFactoryResolver
3638
.resolveComponentFactory(component)
3739
.create(this.injector, resolvedContent);
38-
3940
this.appRef.attachView(componentRef.hostView);
4041

4142
const domElem = (componentRef.hostView as EmbeddedViewRef<any>)
@@ -46,16 +47,15 @@ export class FivOverlayService {
4647
return componentRef;
4748
}
4849

49-
private resolveNgContent<T>(content: NgContent<T>) {
50+
private resolveNgContent<T>(
51+
viewContainerRef: ViewContainerRef,
52+
content: NgContent<T>
53+
) {
5054
if (!content) {
5155
return;
5256
}
53-
if (typeof content === 'string') {
54-
const element = this.renderer.createText(content);
55-
return [[element]];
56-
}
5757
if (content instanceof TemplateRef) {
58-
const viewRef = content.createEmbeddedView(null);
58+
const viewRef = viewContainerRef.createEmbeddedView(content);
5959
return [viewRef.rootNodes];
6060
}
6161

src/app/pages/dialog/dialog.page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
<ion-card-header>
6464
<ion-card-subtitle>Awesome Subtitle</ion-card-subtitle>
65-
<ion-card-title>Awesome Title</ion-card-title>
65+
<ion-card-title>{{'Awesome Title' | uppercase }}</ion-card-title>
6666
</ion-card-header>
6767
<ion-card-content>
6868
<p>The content for this dialog</p>

src/app/pages/feature-discovery/feature-discovery.page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
<div padding>
7676
<ion-text color="light">
7777
<h1>Go Back</h1>
78-
<p>Leave this page by clicking the back arrow.</p>
78+
<p>{{'Leave this page by clicking the back arrow.' | uppercase}}</p>
7979
</ion-text>
8080
<ion-buttons>
8181
<ion-button (click)="back.hide(); fab.show()" color="light" shape="round" fill="outline">

0 commit comments

Comments
 (0)