Created
May 22, 2018 21:17
-
-
Save jschwarty/8d5d42069c24d5ecc99aab6447ba68a2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 } from '@angular/core'; | |
class NgxLetContext { | |
ngxLet: any; | |
} | |
/* | |
* Example usage | |
* <ng-container *ngxLet="person$ | async as person"> | |
* <h1>{{person.name}}</h1> | |
* <p>{{person.description}}</p> | |
* </ng-container> | |
*/ | |
@Directive({ | |
selector: '[ngxLet]' | |
}) | |
export class NgxLetDirective { | |
private _context: NgxLetContext = new NgxLetContext(); | |
constructor( | |
viewContainerRef: ViewContainerRef, | |
templateRef: TemplateRef<NgxLetContext> | |
) { | |
viewContainerRef.createEmbeddedView(templateRef, this._context); | |
} | |
@Input() | |
set ngxLet(value: any) { | |
this._context.ngxLet = value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment