【发布时间】:2021-01-20 11:31:12
【问题描述】:
单击选项卡栏中的第二个选项卡会显示此错误:
core.js:6241 ERROR Error: Uncaught (in promise): TypeError: this.networkService.getRequest(...).pipe is not a function
TypeError: this.networkService.getRequest(...).pipe is not a function
at PaymentService.getPaymentList (payment.service.ts:359)
at PaymentComponent.loadDataPaymentState (payment.component.ts:188)
at PaymentComponent.ngAfterViewInit (payment.component.ts:130)
这些选项卡中的两个页面正在使用 PaymentComponent。一切都在第一次打开的选项卡中工作。单击第二个选项卡会导致错误。
发生错误的代码是:
getpaymentList() {
let list = this.buildListURL();
return this.networkService.getRequest(list).pipe(
tap(
(data) => {
console.log(data);
this.lastbill= data["bill"];
},
(error) => {
console.log(" error");
console.log(error);
}
)
);
}
getRequest的代码:
getRequest(path, customHeader?) {
let options = this.createOptions();
if (customHeader) {
options.headers = this.jsonConcat(options.headers, customHeader);
}
if (!this.isOnline) {
this.errorOccurred(null);
}
let cachedData = this.cacheService.getCachedNode(path);
if (cachedData) {
return cachedData;
} else {
return this.http
.get(
path,
options
)
.pipe(
map(
(data) => {
console.log("data");
return data;
},
(error) => {
console.log("error");
console.log(error);
this.errorOccurred(error);
}
)
);
}
}
我无法弄清楚问题所在。如果有人对此有任何想法,请告诉我。谢谢
【问题讨论】:
-
将
getRequest(path, customHeader?)更改为getRequest(path, customHeader?): Observable<YourType>并告诉我们它是否可以解决您的管道问题,但会破坏您的getRequest方法。 -
@Silvermind 在将 getRequest(path, customHeader?) 更改为 getRequest(path, customHeader?) 后给出相同的错误:Observable
-
您的输入可能有误。尝试禁用缓存系统并始终返回 http 逻辑。如果这样可以解决问题,您应该检查您的缓存机制。
-
@Silvermind 你是对的,禁用缓存后缓存机制有问题
-
听起来 cachedData 无法通过管道输出。你可以尝试用 RxJS 运算符包装它吗:return of(cachedData) ?
标签: angular ionic-framework rxjs ionic4 rxjs-observables