如何将json响应对象的特定数据类型存储在数组中(例如:数字),以作为变量传入数据源
在应用程序中的某个位置声明类型,例如在服务中:如何将json响应对象的特定数据类型存储在数组中(例如:数字),以作为变量传入数据源,json,angular,typescript,Json,Angular,Typescript,在应用程序中的某个位置声明类型,例如在服务中: export class AppComponent implements OnInit { title: String = "Heatmap"; constructor(private app:AppServiceService) { } ngOnInit(): void { this.app.getdata().subscribe ( (re
export class AppComponent implements OnInit {
title: String = "Heatmap";
constructor(private app:AppServiceService) { }
ngOnInit(): void {
this.app.getdata().subscribe
(
(response)=>{console.log(response)}
)
}
dataSource: Object []= [
[1, this.num.value, 9, 23, 0, 39, 0],
[0, 18, 37, 0, 0, 50, 0]
];
}
如果响应具有简单类型,则可以直接使用它:
ngOnInit() {
this.appService.getData().subscribe((response: GetDataResponse) => {
console.log(response);
})
}
你能提供更多的细节吗。
ngOnInit() {
this.appService.getData().subscribe((response: GetDataResponse) => {
console.log(response);
})
}
ngOnInit() {
this.appService.getData().subscribe((response: {data: number[]}) => {
console.log(response);
})
}