我一直試圖在離子中創建一個指令,它只是不工作,我似乎不知道爲什麼。 我希望指令允許自動調整自身的大小。所以當它有更多的文本時,它只是不斷調整大小。Ionic 3指令不工作
這是我的代碼: 而我的項目是一個離子3項目,它使用角度4,新版本。
import { Directive, HostListener, ElementRef } from '@angular/core';
@Directive({
selector: '[auto-resize-text-input]' // Attribute selector
})
export class AutoResizeTextInput {
constructor(public elem: ElementRef) {
console.log('Hello AutoResizeTextInput Directive');
}
@HostListener('input', ['$event.target']) onInput() {
this.resizeTextOnInput();
}
private resizeTextOnInput() {
this.elem.nativeElement.style.overflow = 'hidden';
this.elem.nativeElement.style.height = 'auto';
this.elem.nativeElement.style.height = this.elem.nativeElement.scrollHeight + "px";
}
}
請幫助????
嗨,你找到了解決方案嗎? – Yasir
還沒有找到任何解決方案,前往離子論壇問,仍然沒有解決方案 –
希望你可以在這裏找到答案 - https://chat.stackoverflow.com/rooms/153499/ionic-3 –