To transfer values of
this.bookingInfo = bookings.responseObj.txnValues;
array from the parent component to the bookingInfo array in my child component and then insert that data into the chartNameChartTTV.data = [];
array in the child component. Here, divName
will be referencing an HTML file am4core.create('divName', am4charts.XYChart);
rather than the bookingInfo array.
This code belongs to my parent component.
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent implements OnInit{
bookingInfo = [];
ngOnInit() {
this.getBookingInfo();
}
getBookingInfo() {
const params = [];
params.push({code: 'dateType', name: 'BOOKING'});
params.push({code: 'fromDate', name: '2019-01-01'});
params.push({code: 'toDate', name: '2019-12-31'});
this.ServiceHandler.getTxnInfo([], params).subscribe(
bookings => {
this.bookingInfo = bookings.responseObj.txnValues;
console.log(this.bookingInfo);
});
}
}
This code is from my child component.
@Component({
selector: 'app-summary-chips',
templateUrl: './summary-chips.component.html',
styleUrls: ['./summary-chips.component.scss']
})
export class SummaryChipsComponent implements OnInit {
@Input() bookingInfo: [];
ngOnInit() {
console.log(this.bookingInfo);
}
createSummaryChips( divName: string, chartDataInfo: [], chartValue: any, chartDate: any) {
am4core.useTheme(am4themesAnimated);
const chartNameChartTTV = am4core.create('divName', am4charts.XYChart);
chartNameChartTTV.width = am4core.percent(100);
chartNameChartTTV.height = am4core.percent(100);
chartNameChartTTV.padding(0, 0, 0, 0);
chartNameChartTTV.data = [];
}
}
This is my service class.
@Injectable({
providedIn: 'root'
})
export class ServiceHandler {
getTxnInfo(headers: any[], params: any[]) {
return this.apiService.get( 'analytics-api/dashboard/txn-info', headers, params);
}
}
However, when I attempt to console.log(this.bookingInfo);
in the child component, it displays an error indicating "undefined". This is the content from my dashboard.component.html file.
<div class="l-content-wrapper c-summary-chip oh" >
<div class="c-summary-chip__txt">Cancellations</div>
<div id="divName" class="c-summary-chip__graph ">
</div>
</div>
However, I wish to move this code block to summary-chips.component.html and include in dashboard.component.html like this:
<div class="l-content-wrapper c-summary-chip oh" style="visibility: hidden">
<app-summary-chips></app-summary-chips>
</div>