【发布时间】:2018-12-30 00:21:18
【问题描述】:
我在函数中有这部分:
this.myservice.getComments()
.subscribe(data => {
this.post.comments = data.body;
this.post.comments_count = Number(data.headers.get('x-wp-total'));
this.post.comments_pages = Number(data.headers.get('x-wp-totalpages'));
this.content_ready = true;
});
getComments 函数:
export class myservice extends DataService {
protected url = 'my_url';
constructor( protected http: HttpClient ) {
super(http);
}
getComments(){
return this.get(
this.subUrl, true );
}
}
dataService的相关部分:
export class DataService {
protected url: string;
constructor(protected http: HttpClient) {}
get(subUrl:string = '', needObservable = false) {
let options = {};
if(needObservable) {
options = {observe: 'response'};
}
return this.http.get(this.url + subUrl, options);
}
}
所有这些都运行良好。问题是,我的 IDE (phpstorm) 抱怨 data.headers 和 data.body,认为这些属性在“对象”类型上不存在。
如何让它知道一切都很好?我想过输入返回值,但没有成功。
【问题讨论】:
标签: angular typescript rxjs