title: Ionic 4 - getting ElementRef property on Directive
body: <p>I need get ElementRef value in a Directive to apply dynamically a class to the element.</p>
  
  <p>My Directive:</p>
  
  <pre><code>import { Directive, ElementRef, Renderer2 } from '@angular/core';
  
  @Directive({
    selector: '[scrolling]'
  })
  
  export class ScrollingDirective {
  
    constructor(public renderer: Renderer2, public el: ElementRef) {
      console.log(this.el);
      console.log(this.el.nativeElement.scrollWidth);
      if (el.nativeElement.scrollWidth &gt; el.nativeElement.clientWidth) {
        this.renderer.addClass(el.nativeElement, 'scrollear');
      }  
    }
  
  }
  </code></pre>
  
  <p>Then I assign the directive to a DOM's element:</p>
  
  <pre><code>&lt;ion-label scrolling&gt;hello world&lt;/ion-label&gt;
  </code></pre>
  
  <p>The problem is that in the constructor of the directive I cannot receive the values ​​of the element, however, with console.log I can see the values ​​correctly, but I can't get them.</p>
  
  <p>I need to retrieve these values, but when referencing them the value is 0.</p>
  
  <p><a href="https://i.stack.imgur.com/Yz6FZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Yz6FZ.png" alt="console.log(this.el);"></a></p>