将数据发布到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/