gpt4 book ai didi

android - 如何在ionic2中重新加载api url

转载 作者:行者123 更新时间:2023-11-29 11:48:03 24 4
gpt4 key购买 nike

将数据发布到 api url 后。我想刷新 api url 以获取最后更新的数据

我是这样称呼自己的

this.http.get('api url here',{headers: headers}).map(res => res.json()).subscribe(data => {
this.items=data;
},
err => {
console.log('Err!')
});

请给点建议

最佳答案

试试这个:

添加提供者:

 @Injectable()
export class ServiceProvider {

baseUrl: string = 'https://...';

constructor(public http: Http) {
this.http = http;
}

getPosts(){
return this.http.get(this.baseUrl)
.map(res => res.json())
.toPromise();// executa uma function e retorna JSON
}

然后在首页:

 ngOnInit(){
this.getPostsSite();
}

getPostsSite(){
this.serviceProvider.getPosts().then(
response => {
this.items = response.data.children
});

}

关于android - 如何在ionic2中重新加载api url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42485447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com