将数据发布到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
});
}