Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c56de31

Browse files
ChauChau
Chau
authored and
Chau
committed
feat(core/dom): expose HTMLCanvasElement and host element through template context
1 parent 8d31240 commit c56de31

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

libs/core/dom/src/lib/canvas.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ import { createPointerEvents } from './events';
5151
export class NgtCanvasContent {
5252
private canvas = inject(NgtCanvasImpl);
5353

54-
get host() {
55-
return this.canvas['host'].nativeElement;
56-
}
57-
5854
constructor() {
5955
const store = injectStore();
6056
const vcr = inject(ViewContainerRef);
@@ -64,6 +60,13 @@ export class NgtCanvasContent {
6460
commentNode.data = NGT_CANVAS_CONTENT_FLAG;
6561
commentNode[NGT_CANVAS_CONTENT_FLAG] = store;
6662
}
63+
64+
static ngTemplateContextGuard(
65+
_: NgtCanvasContent,
66+
ctx: unknown,
67+
): ctx is { $implicit: HTMLCanvasElement; host: HTMLElement } {
68+
return true;
69+
}
6770
}
6871

6972
@Component({
@@ -246,7 +249,11 @@ export class NgtCanvasImpl {
246249
this.store.snapshot.events.connect?.(canvasElement);
247250
}
248251

249-
this.glRef = canvasVcr.createEmbeddedView(canvasContent, {}, { injector: this.injector });
252+
this.glRef = canvasVcr.createEmbeddedView(
253+
canvasContent,
254+
{ $implicit: canvasElement, host: this.host.nativeElement },
255+
{ injector: this.injector },
256+
);
250257
this.glRef.detectChanges();
251258
}
252259
}

0 commit comments

Comments
 (0)