I have two components and one with an attribute selector. Children's component -
import { Component, OnInit, Input, ElementRef } from '@angular/core'; @Component({ selector: '[app-bar-chart]', templateUrl: './bar-chart.component.html', styleUrls: ['./bar-chart.component.css'] }) export class BarChartComponent implements OnInit { @Input() chartContainer: ElementRef; @Input() title: string; @Input() chartData: { title: string, content: { label: string, value: number, fill?: string }[] }[]; constructor() { } ngOnInit() { console.log(this.chartContainer); console.log(this.chartContainer.nativeElement); } }
Parent component:
import { Component, OnInit, Output, ViewChild, ElementRef } from '@angular/core'; @Component({ selector: 'app-dashboard', template: `<div><div class="graph-image" style="width: 100%; height: 400px;" app-bar-chart [title]="barChartTitle" [chartData]="ChartData" [chartContainer]="chartContainer" #chartContainer></div></div>`, styleUrls: ['./dashboard.component.css'] }) export class DashboardComponent implements OnInit { barChartTitle = 'Transaction History'; ChartData = [ { "title": "May2017", "content": [ { "label": "payable", "value": 10 } ] }, { "title": "Jun2017", "content": [ { "label": "payable", "value": 120 } ] } ]; constructor() { } ngOnInit() { } }
I am passing a local link from the parent component to the child component. When I console my own element of this local link, it is "undefined". How can I access my own element to access the width and height of the style of the div component.
source share