1
0

Added ng-let directive

This commit is contained in:
2020-05-13 12:54:45 -04:00
parent b5e0c808e6
commit 6e842bc392
2 changed files with 51 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
import { NgModule } from '@angular/core';
import { NgLetDirective } from './ng-let.directive';
const exportedDirectives = [
NgLetDirective
];
@NgModule({
declarations: [
...exportedDirectives
],
exports: [
...exportedDirectives
]
})
export class DirectivesModule { }

View File

@@ -0,0 +1,34 @@
import {
Directive,
Input,
OnInit,
TemplateRef,
ViewContainerRef
} from '@angular/core';
export class NgLetContext {
$implicit: any = undefined;
ngLet: any = undefined;
}
@Directive({
// tslint:disable-next-line:directive-selector
selector: '[ngLet]'
})
export class NgLetDirective implements OnInit {
private readonly _context = new NgLetContext();
@Input()
set ngLet(value: any) {
this._context.$implicit = this._context.ngLet = value;
}
constructor(
private readonly _vcr: ViewContainerRef,
private readonly _templateRef: TemplateRef<NgLetContext>
) { }
ngOnInit(): void {
this._vcr.createEmbeddedView(this._templateRef, this._context);
}
}