结合我有这个指令取决于其含量设定了一个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