angular 템플릿에 임시 변수 설명하기 (명령 실행)
1620 단어 angular2/4
import { Directive, ViewContainerRef, TemplateRef, Input } from '@angular/core';
@Directive({
selector: '[let]'
})
export class ExpAsDirective {
_context: any = {};
@Input() public set letContext(val) {
this._context = val;
this._updateView();
}
constructor(private _viewContainer: ViewContainerRef, templateRef: TemplateRef) {
this._thenTemplateRef = templateRef;
}
private _updateView() {
this._viewContainer.clear();
this._viewContainer.createEmbeddedView(this._thenTemplateRef, this._context);
}
}
사용
<div *let="let tt1 = tt;let age1 = age;context: {tt: name, age: 12}">{{tt1}}-------{{age1}}div>
<input [(ngModel)]="name">
ngTemplateOutlet과 동일한 방법 사용