Skip to content

Instantly share code, notes, and snippets.

@jschwarty
Created May 22, 2018 21:17
Show Gist options
  • Save jschwarty/8d5d42069c24d5ecc99aab6447ba68a2 to your computer and use it in GitHub Desktop.
Save jschwarty/8d5d42069c24d5ecc99aab6447ba68a2 to your computer and use it in GitHub Desktop.
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