TypeError: this.networkService.getRequest(...).pipe is not a function in ionic Angular
TypeError: this.networkService.getRequest(...).pipe is not a function in ionic Angular
单击选项卡栏中的第二个选项卡显示此错误:
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 方法时,调用方法需要一个可观察对象,缓存中没有数据,而 else 子句中没有数据 被调用但是当下次调用此函数时缓存中有数据并且 if (cachedData) 子句 被调用但是
if (cachedData) {
return cachedData;
}
没有返回 observable。
如果您对其进行小的改动,那么它也可以与缓存代码一起使用。您必须执行以下操作:
第一个:
import { of } from "rxjs";
对 getRequest 方法进行少量更改,而不是
if (cachedData) {
return cachedData;
}
写
if (cachedData) {
return of(cachedData);
}
单击选项卡栏中的第二个选项卡显示此错误:
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 方法时,调用方法需要一个可观察对象,缓存中没有数据,而 else 子句中没有数据 被调用但是当下次调用此函数时缓存中有数据并且 if (cachedData) 子句 被调用但是
if (cachedData) {
return cachedData;
}
没有返回 observable。
如果您对其进行小的改动,那么它也可以与缓存代码一起使用。您必须执行以下操作:
第一个:
import { of } from "rxjs";
对 getRequest 方法进行少量更改,而不是
if (cachedData) { return cachedData; }
写
if (cachedData) {
return of(cachedData);
}