【发布时间】:2019-10-21 11:12:23
【问题描述】:
我知道这已经被问过很多次了,但是,我无法弄清楚如何使用以下帖子更改我自己的代码。
Property 'subscribe' does not exist on type 'OperatorFunction<Response, Recipe[]>'
Property 'subscribe' does not exist on type 'OperatorFunction<Product[], ParamMap>'
Property 'subscribe' does not exist on type 'OperatorFunction<unknown, any>'
rest-api.service.ts
specificObjectRequest(ids: string[]): Observable<any> {
var idString = ids.join();
const url = `${ApiServerUrl}/media_objects?ID=${idString}`;
console.log("requesting from url: " + url);
this.http.get(url, {}, {})
.then(res => this.extractData = res.data)
.catch(this.handleError);
return;
}
tagRequest(topic: string){
var url = `${ApiServerUrl}/tags?topic=${topic}`;
url = encodeURI(url);
console.log("requesting from url: " + url);
this.http.get(url, {}, {})
.then(res => this.extractData = res.data)
.catch(this.handleError);
return map(this.extractData);
}
我使用官方文档https://ionicframework.com/docs/native/http 和本教程创建了这个请求
filter.page.ts
async requestMapTags(topic: string){
await this.api.tagRequest(topic).subscribe(res => { //Property 'subscribe' does not exist on type 'OperatorFunction<Response, {}>'
console.log(res);
this.tagsRequestAnswer = res;
}, err => {
console.log(err);
});
}
错误信息:
[ng] ERROR in src/app/filter/filter.page.ts(89,35): error TS2339: Property 'subscribe' does not exist on type 'OperatorFunction<Response, {}>'.
从我的阅读来看,这是 Promises 和 rxjs 之间的冲突。
问题: 我需要更改什么才能使其正常工作?有没有办法在我的代码中添加所需的“管道”函数以使其工作?
【问题讨论】:
-
tagRequest 函数在哪里?还有为什么你只在 specificObjectRequest 中使用 return ?
-
我添加了 tagRequest
标签: javascript angular typescript ionic-framework