我有一个组件在这里声明数字数组 public numbers :number[] =[];
并在服务响应中给出数字数组的值并获得 10 并且在 ngInit 块之后它显示为未定义
app.component.ts
export class AppComponent implements OnInit {
public numbers :number[] =[]; // here declare the variable
public numberss :Iproduct[]
ngOnInit(){
// here call the service
this._productService.getproducts().subscribe((response) => {this.numberss = response;
this.errornumber = 10; // here ressign the value
}
}),(err)=> {this.errorMsg =<any>err};
} // end of ngInit
// here is the 3rd party chart js pass the this.errornumber gets undefined
public doughnutChartOptions: any = {
elements: {
center: {
text:this.errornumber +"% <br>products" ,
}
}
};
} // end of component
这里未定义原因:text:this.errornumber