Skip to content

Instantly share code, notes, and snippets.

@d3lm
Created August 24, 2018 06:07
Show Gist options
  • Save d3lm/331373e0a5c7ff4fef61ecb8878d1eee to your computer and use it in GitHub Desktop.
Save d3lm/331373e0a5c7ff4fef61ecb8878d1eee to your computer and use it in GitHub Desktop.
*ngLet Directive
import { Directive, Input, TemplateRef, ViewContainerRef, OnInit } from '@angular/core';
export class NgLetContext {
$implicit: any = null;
ngLet: any = null;
}
@Directive({
selector: '[ngLet]'
})
export class NgLetDirective implements OnInit {
private _context = new NgLetContext();
@Input()
set ngLet(value: any) {
this._context.$implicit = this._context.ngLet = value;
}
constructor(private _vcr: ViewContainerRef, private _templateRef: TemplateRef<NgLetContext>) {}
ngOnInit() {
this._vcr.createEmbeddedView(this._templateRef, this._context);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment