1
0
This repository has been archived on 2025-11-02. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
comment-system/src/app/directives/ng-let-directive.ts

34 lines
698 B
TypeScript

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);
}
}