StoreModule.forFeature 不存在

StoreModule.forFeature does not exist

我正在尝试获取现有的 ngrx 存储状态并将其重构为子功能 modules.The 问题是当我在我的功能模块导入中使用 StoreModule.forFeature 时...我在执行过程中遇到错误编译:

ERROR in [at-loader] ./src/app/components/login/login.module.ts:67:21
TS2339: Property 'forFeature' does not exist on type 'typeof StoreModule'.

我实际上已经在 node_modules/@ngrx/store 中搜索了 "forFeature",但没有找到任何结果。然后我重新安装了@ngrx/store 和@ngrx/core,仍然没有搜索到 'forFeature' 的结果。我检查了文档,'forFeature' 仍然在文档列表中列出,而不是 depracted。

导入语句如下:

import {StoreModule} from "@ngrx/store";
import {reducers} from "./rdx/reducers/index"; ...
@NgModule({
imports: [StoreModule.forFeature('loginFeature',reducers)]
...
}

包json中显示的使用o NGRX的版本如下:

"@ngrx/core": "^1.2.0",
"@ngrx/store": "^2.2.3",

还搜索了 google 这个问题,但没有结果。仅针对我已经使用的 "forRoot" 到 "provideStore" 的贬低结果。

您的代码还有其他问题。

错误不说"Property 'forFeature' does not exist on type StoreModule"

它说 "Property 'forFeature' does not exist on type TYPEOF StoreModule"(应该是未定义的)。

解决了这个问题。 问题是:

  1. 当我安装 ngrx 时,它会自动安装最新版本的 ngrx,意思是 2.2.3,要安装我必须使用的最新版本npm install --save @ngrx/store@latest @ngrx/core@latest 安装了 "@ngrx/store": "^5.2 .0"

  2. ngrx 的文档 - 在他们的 github 文档中,他们指示您专门安装 ngrx,如下所示: npm install @ngrx/core @ngrx/store@2.2.3 --save,安装下link可以看到这个:https://github.com/ngrx/store