我花了几个小时试图弄清楚如何在x-total-objects
之后获得标头响应和状态代码http.get
,我有这个类服务,我需要访问这些属性来对我的结果进行分页
在役:
@Injectable()
export class WPCollections{
constructor(private http: Http){ }
fetch(url){
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.get(url, options).map(res => res.json());
}
}
在组件中:
@Input() args;
posts = new Array<any>();
service: Observable<any>;
constructor(private wp: WPCollections) { }
fetchData(args){
this.service = this.wp.fetch(args);
this.service.subscribe(
collection=>{
this.posts = collection;
},
err => this.onError(err)
);
}