結合我有這個指令取決於其含量設定了一個textarea流體高度:角2檢測變爲只讀輸入的[ngModel]在指令
@Directive({
selector: '[fluidHeight]',
host: {
'(ngModelChange)': 'setHeight()'
}
})
export class FluidHeightDirective implements AfterViewInit {
constructor(private elementRef: ElementRef) {}
ngAfterViewInit() {
this.setHeight();
}
@HostBinding('style.height.px')
height: number;
setHeight() {
console.log(true)
this.height = this.elementRef.nativeElement.scrollHeight;
}
}
但是我不能讓它
<textarea [ngModel]="foo" fluidHeight readonly></textarea>
還有一個textarea的這改變了readonly
輸入的內容:當我使用[ngModel]
與readonly
一起工作。
我試過使用ngModelChange
,change
和input
但他們都沒有工作。
有誰知道如何做到這一點?
是'foo'您的內容? – Dinistro
@Dinistro是的。 – Chrillewoodz