在这里,我希望将this.bookingInfo = bookings.responseObj.txnValues; this.bookingInfo数组值的值从父组件传递给子组件中的bookingInfo数组,我想将这些数据放入子组件中的component.And数组中。在这里,divName将访问html文件am4core.create('divName', am4charts.XYChart);,而不是bookingInfo数组。
这是我的父组件。
@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);
});
}
}这是我的子组件。
@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 = [];
}
}这是我的服务类。
@Injectable({
providedIn: 'root'
})
export class ServiceHandler {
getTxnInfo(headers: any[], params: any[]) {
return this.apiService.get( 'analytics-api/dashboard/txn-info', headers, params);
}
}但是,当我尝试在子组件中定义时,它显示了一个错误,如console.log(this.bookingInfo); This is 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>但是我想把这个代码块放到summary-chips.component.html中,然后放入
像这样的dashboard.component.html文件
<div class="l-content-wrapper c-summary-chip oh" style="visibility: hidden">
<app-summary-chips></app-summary-chips>
</div>发布于 2020-04-18 10:39:02
您只需将bookingInfo从仪表板输入到应用摘要芯片输入中即可
在仪表板组件的html中:
<div class="l-content-wrapper c-summary-chip oh" style="visibility: hidden">
<app-summary-chips [bookingInfo]='bookingInfo'></app-summary-chips>
</div>https://stackoverflow.com/questions/61277229
复制相似问题