I am trying to write a directive in angular2 + typescript that makes tooltip to show only when ellipsis is active (show complete text pop up only when its not fully displayed, and ends with "..." ). I found this answer in stackoverflow:
show the tooltip only when ellipsis is active
Now I'm trying to translate this Jquery function:
To typescript. so far this is what I got:
import { Directive, ElementRef } from '@angular/core';
@Directive({ selector: '[isEllipsisActive]' })
export class IsEllipsisActiveDirective {
constructor(el: ElementRef) {
if (el.nativeElement.classList.contains('className')) {
if (this.isEllipsisActive(el.nativeElement)) {
//el.nativeElement.attributes("title",el.nativeElement.text());
}
}
}
isEllipsisActive(e: any) {
return (e.offsetWidth < e.scrollWidth);
}
}
I can't figure out how to get the text from the element and pass it on to the element's title using typescript. any ideas?
Thanks!