I have an Angular directive that adds styling text-overflow: ellipsis; overflow: hidden; white-space: nowrap;
in ngOnInit
and then looks something like this:
@Directive({ selector: 'ellipsis' })
class EllipsisDirective {
ngAfterViewInit() {
const el: HTMLElement = this.el.nativeElement;
if (el.offsetWidth < el.scrollWidth) {
el.setAttribute('title', el.innerText);
}
}
}
Usage: <div ellipsis>Some Very Long Text Here</div>
The problem:
On some pages, the layout/components do not change on a 'navigate', only the data does. Currently the directive does not pick up the difference in el.innerText
and thus keeps the old .title
property.
I've also tried using an Input()
and work with with ngOnChanges()
. I'd prefer to not use an input though.
I can make it work with the input and a setTimeout
but that can hardly be the way to go.