我正在尝试从方法中获取值并将其用于图形但是当我尝试获取值时,它显示为null。
TS
`bgs= [];
getbgs() {
this.bgsService.getbgss(this.token).subscribe(
data => {
this.bgs = data.map(k => k.bgs);
console.log(this.bgs); // I can get the value here
}
);
}
public lineChartData: Array<any> = [
{ data: [this.bgs], label: 'Series A' },
console.log("chart:" + this.bgs) // here the bgs is showing null .
];`
这样做。
bgs= [];
public lineChartData: Array<any>
ngOnInit(){
this.lineChartData = []
. . .
}
getbgs() {
this.bgsService.getbgss(this.token).subscribe(
data => {
this.bgs = data.map(k => k.bgs);
this.lineChartData = [
{ data: [this.bgs], label: 'Series A' }
]
}
);
}