I have a view which contains a < svg > element inside < ng-template>
<div *ngIf="data == undefined; else elseBlock">
   Sorry no data!
</div>
<ng-template #elseBlock>
   <svg id="areachart" width="100%" height="210"></svg>
</ng-template>
Using d3, I am trying to read width(baseValue) of the svg element, but d3.select('#areachart') returns me null in the code:
export class DrawAreaChart implements AfterViewInit {
    private data;
    constructor(){}
    ngAfterViewInit() {
       this.chartService.getData().subscribe(
           (result) => {
               if (result) {
                  this.data = result;
                  var svg = d3.select("#areachart"),
                  width = +svg.property("width").baseVal.value, /* The code fails here */
                  height = +svg.property("height").baseVal.value;
                  ....
                  ....
               }
           }
       );
    }
    ....
    ....
    ....
}
It throws error saying-
Cannot read property 'width' of null
Please help.
 
    