我一直试图在离子中创建一个指令,它只是不工作,我似乎不知道为什么。 我希望指令允许自动调整自身的大小。所以当它有更多的文本时,它只是不断调整大小。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 –