NgRx选择器返回初始状态,修复后遇类型匹配报错求助
NgRx新手问题:选择器返回空白初始状态而非API请求数据
- 我是NgRx新手,当前遇到的问题是:选择器返回空白初始状态,而非Effects中API请求获取的数据。在
home.component.ts中使用选择器时,得到如下输出:
homepage.component - global state - books is ["", {…}, 4, true, …] 0: "" 1: Object 2: 4 3: true 4: "" homepage.component - global state - pokemon is ["", {…}, 4, true, …] 0: "" 1: Object 2: 4 3: true 4: ""
- 确认Effects中的API调用正常,能获取到数据。
- 已搭建可复现问题的示例,只需取消注释代码中“// Global State Calls Do Not Work”部分即可触发问题。
编辑补充:
我已修复选择器,并且处理了booksLoaded动作,但出现了新的类型错误:No overload matches this call.
Overload 1 of 2, '(observerOrNext?: Partial| ((value: BooksState) => void) | undefined): Subscription', gave the following error.
Argument of type '(res: Book[]) => void' is not assignable to parameter of type 'Partial| ((value: BooksState) => void) | undefined'. 我怀疑
book.reducer中Bookstate extends Book的写法没有达到预期效果...
内容的提问来源于stack exchange,提问作者Scottish Smile
相关产品推荐
相关产品推荐

