【发布时间】:2017-09-07 13:32:21
【问题描述】:
我一直在尝试在 ionic 中创建一个指令,但它只是不起作用,我似乎不知道为什么。 我希望该指令能够自动调整自身大小。因此,当它有更多文本时,它只会不断调整大小。
这是我的代码: 我的项目是一个ionic 3项目,它使用了新版本的angular 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";
}
}
请帮忙????
【问题讨论】:
-
嗨,您找到解决方案了吗?
-
No 还没找到解决办法,去离子论坛问问还是没有解决办法
-
希望你能在这里找到答案 - chat.stackoverflow.com/rooms/153499/ionic-3
标签: angular typescript ionic2