gpt4 book ai didi

angular - 错误错误 : Uncaught (in promise): TypeError: Cannot read property 'map' of undefined

转载 作者:搜寻专家 更新时间:2023-10-30 21:59:19 26 4
gpt4 key购买 nike

以下错误仅在它尝试从 catch 返回值时发生。希望我在这里做的是根本错误的事情。请给我一个线索。为什么我不能从 catch 返回一个 observable

.ts

  getMyTopic() {
return this.topicSer.getMyTopics().map((res: any) => res.json()).map((res: any) => res = res.categories)
.catch((err: any) => {
console.log('err', err);
return []
})
}

provider.ts

  getMyTopics(): Observable<any> {
if (typeof this.userService.userDetails != 'undefined') {
this.localCacheService.getItem(this.localCacheService.discoverTopicsKey).then((val) => {
if (val != null && val.length == 0) return this.apiService.get(config.discover_topic_WITHAUTH);
}).catch(() => {
return this.apiService.get(config.discover_topic_WITHOUTAUTH);//here is the issue
});
}

错误

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'map' of undefined
TypeError: Cannot read property 'map' of undefined
at Discover.webpackJsonp.402.Discover.getMyTopic (discover.ts:123)
at Discover.webpackJsonp.402.Discover.getData (discover.ts:69)
at discover.ts:51
at t.invoke (polyfills.js:3)
at Object.onInvoke (core.js:4626)
at t.invoke (polyfills.js:3)
at r.run (polyfills.js:3)
at polyfills.js:3
at t.invokeTask (polyfills.js:3)
at Object.onInvokeTask (core.js:4617)
at Discover.webpackJsonp.402.Discover.getMyTopic (discover.ts:123)
at Discover.webpackJsonp.402.Discover.getData (discover.ts:69)
at discover.ts:51
at t.invoke (polyfills.js:3)
at Object.onInvoke (core.js:4626)
at t.invoke (polyfills.js:3)
at r.run (polyfills.js:3)
at polyfills.js:3
at t.invokeTask (polyfills.js:3)
at Object.onInvokeTask (core.js:4617)
at c (polyfills.js:3)
at polyfills.js:3
at t.invokeTask (polyfills.js:3)
at Object.onInvokeTask (core.js:4617)
at t.invokeTask (polyfills.js:3)
at r.runTask (polyfills.js:3)
at o (polyfills.js:3)
at e.invokeTask [as invoke] (polyfills.js:3)
at p (polyfills.js:2)
at IDBRequest.v (polyfills.js:2)
defaultErrorLogger @ core.js:1350
ErrorHandler.handleError @ core.js:1411
IonicErrorHandler.handleError @ ionic-error-handler.js:61
next @ core.js:5373
schedulerFn @ core.js:4220
SafeSubscriber.__tryOrUnsub @ Subscriber.js:238
SafeSubscriber.next @ Subscriber.js:185
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ core.js:4200
(anonymous) @ core.js:4648
t.invoke @ polyfills.js:3
r.run @ polyfills.js:3
NgZone.runOutsideAngular @ core.js:4574
onHandleError @ core.js:4648
t.handleError @ polyfills.js:3
r.runGuarded @ polyfills.js:3
(anonymous) @ polyfills.js:3
n.microtaskDrainDone @ polyfills.js:3
o @ polyfills.js:3
e.invokeTask @ polyfills.js:3
p @ polyfills.js:2
v @ polyfills.js:2
IndexedDB (async)
(anonymous) @ localforage.js:826
t.invoke @ polyfills.js:3
onInvoke @ core.js:4626
t.invoke @ polyfills.js:3
r.run @ polyfills.js:3
(anonymous) @ polyfills.js:3
t.invokeTask @ polyfills.js:3
onInvokeTask @ core.js:4617
t.invokeTask @ polyfills.js:3
r.runTask @ polyfills.js:3
o @ polyfills.js:3
e.invokeTask @ polyfills.js:3
p @ polyfills.js:2
v @ polyfills.js:2

最佳答案

getMyTopics 方法不返回任何内容。此外,catch 运算符在应该返回 Observable 时返回了一个空数组。

关于angular - 错误错误 : Uncaught (in promise): TypeError: Cannot read property 'map' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47360043/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com