json - 在 IONIC 框架中使用 Angular JS 从 API 访问 JSON 数据
问题描述
大家好,我目前正在开发一个移动应用程序来获取实时的 covid-19 详细信息。为此,我使用了带有 angularjs 的 ionic 框架。我从数据正在获取的API中获取数据。
结果如下。我需要获取重要的详细信息,但我无法访问它。我需要获取 local_new_cases 和 local_total_Cases。
我应该如何得到它?
这是当前输出。我的代码显示在下面。home_page.ts`。这里我没有包含导入模块。
'
export class HomePage {
data: string;
error: string;
loading: any;
constructor(private http: HttpClient,public loadingController: LoadingController) {
this.data = '';
this.error = '';}
async ionViewWillEnter() {'
await this.presentLoading();
// Load the data
this.prepareDataRequest()
.pipe(
finalize(async () => {
// Hide the loading spinner on success or error
await this.loading.dismiss();
})
)
.subscribe(
data => {
// Set the data to display in the template
this.data = JSON.stringify(data);
},
err => {
// Set the error information to display in the template
this.error = `An error occurred, the data could not be retrieved: Status: ${err.status}, Message: ${err.statusText}`;
}
);
}
'async presentLoading()
{
// Prepare a loading controller
this.loading = await this.loadingController.create({
message: 'Loading...''
});
// Present the loading controller
await this.loading.present();
}
private prepareDataRequest(): Observable<object> {
// Define the data URL
//const dataUrl = 'https://api.nigelbpeck.com/';
const dataUrl = 'https://hpb.health.gov.lk/api/get-current-statistical/';
// Prepare the request
return this.http.get(dataUrl);
}
}
解决方案
推荐阅读
- django - 如果在您的购物车中,则从首页隐藏物品
- algorithm - 递归过滤和映射属性列表
- amazon-web-services - 给定特定查询字符串参数值,如何在 Api Gateway 级别重定向?
- javascript - 如何评估雪花存储过程中的语句
- python - Flask-SocketIO 在 Werkzeug 下运行 如何让服务器在 eventlet 上运行?
- python - 使用 networkx 绘制图形时,如何在边缘使用颜色?
- javascript - amcharts第3版如何绘制两个值的变化值
- laravel-6 - 在 Laravel 迁移中更改日期格式
- python - 关于工作人员刷新的python多处理池通知
- java - 在方法中将数组作为参数传递