Skip to content

Instantly share code, notes, and snippets.

@xperiments
Created February 13, 2018 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xperiments/07c72f8dc128435dff6157ca0ba4ffc7 to your computer and use it in GitHub Desktop.
Save xperiments/07c72f8dc128435dff6157ca0ba4ffc7 to your computer and use it in GitHub Desktop.
[[ng][directives]] OneTimeDirective #ng #directive
// https://github.com/angular/angular/issues/14033
@Directive({
selector: '[oneTime]',
})
export class OneTimeDirective {
constructor(template: TemplateRef<any>, container: ViewContainerRef, zone: NgZone) {
zone.runOutsideAngular(() => {
const view = container.createEmbeddedView(template);
setTimeout(() => view.detach());
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment