Created
August 24, 2018 06:07
-
-
Save d3lm/331373e0a5c7ff4fef61ecb8878d1eee to your computer and use it in GitHub Desktop.
*ngLet Directive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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