Skip to content

Instantly share code, notes, and snippets.

@nirkaufman
Last active May 8, 2020 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nirkaufman/482a234f6e1297f3a517dfebc9c6e24a to your computer and use it in GitHub Desktop.
Save nirkaufman/482a234f6e1297f3a517dfebc9c6e24a to your computer and use it in GitHub Desktop.
import {AfterViewInit, Component, OnInit, TemplateRef, ViewChild, ViewContainerRef,} from '@angular/core';
@Component({
selector: 'app-root',
template: `
<div class="container">
<h1 class="display-1">Angular<span class="text-muted">MasterClass</span></h1>
<ng-container #container></ng-container>
<ng-container *ngIf="condition as value">{{ value }}</ng-container>
</div>
`,
})
export class AppComponent implements OnInit, AfterViewInit {
@ViewChild('container', {read: ViewContainerRef}) container: ViewContainerRef;
@ViewChild(TemplateRef) template: TemplateRef<any>;
condition: string;
ngOnInit(): void {
setTimeout(() => {
this.condition = "Resolved!";
}, 3000)
}
ngAfterViewInit(): void {
this.container.createEmbeddedView(this.template)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment