Ionic 3 directive not working
I'm trying to create a directive in ionic and it just doesn't work and I don't seem to know why. I want the directive to be able to be automatically resized. So when it has more text, it just keeps the size.
This is my code: And my project is an ionic 3 project that uses angular 4, newer version.
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";
}
}
Please, help????
+3
source to share
3 answers