Get the text from the DOM element and paste it into the 'title' typescript

I am trying to write a directive in angular2 + typescript, which makes the tooltip show only with active ellipsis (show full text only pops up when it is not fully displayed and ends with "..."), I found this answer in stackoverflow:

show tooltip only with active ellipsis

Now I am trying to translate this jQuery function:

In 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 cannot figure out how to get text from an element and pass it to the element title using typescript. any ideas?

Thank!

+4
source share
1

, ElementRef DOM Angular2 doc. Renderer ElementRef, / DOM :

import {Renderer, ElementRef} from '@angular/core;
...
export class IsEllipsisActiveDirective {
constructor {
  private _renderer: Renderer,
  private _el: ElementRef
} (
  //get value
  this._el.nativeElement.querySelector('div/p/whatever...')
  //set value
  this._renderer(_el.nativeElement.querySelector(tag), 'innerHTML', 'Foo')
)

, . " ":

0

Source: https://habr.com/ru/post/1666350/


All Articles