title: How to get width of (DOM) Element in Angular 4 after page is loaded
body: <p>I'm looking for a solution in Angular 4 to get the width of DOM element without taking any action (click or window resize), just after the page is loaded, but before I start to draw the svg. I've found a similar case in <a href="https://stackoverflow.com/questions/43845822/angular-2-get-width-of-a-div">here</a> but it doesn't work for me. I get the same error:</p>
  
  <blockquote>
    <p>ERROR TypeError: Cannot read property 'nativeElement' of undefined</p>
  </blockquote>
  
  <p>I need to get the width of div container to set veiwbox of svg I'm drawing inside it.</p>
  
  <p>Here is the template:</p>
  
  <pre><code>&lt;div id="what-is-the-width" class="svg-chart-container"&gt;
      &lt;svg [innerHTML]="svg"&gt;&lt;/svg&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and TS file with stuff needed in this case:</p>
  
  <pre><code>import { Component, Input, OnInit, ViewEncapsulation, AfterViewInit, ViewChild, ElementRef } from '@angular/core';
  
  export class SvgChartComponent implements OnInit {
  
    @ViewChild('what-is-the-width') elementView: ElementRef;
  
    constructor() { }
  
    ngAfterViewInit() {
      console.log(this.elementView.nativeElement);
    }
  
    ngOnInit() {
      //this method gets the data from the server and draw the svg
      this.getSVGChartData();
    }
  }
  </code></pre>
  
  <p>Does anyone have ideas how to get this working?</p>