1

我试图采用现有的 ngrx 存储状态并将其重构为子功能模块。问题是当我在我的功能模块导入中使用 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”仍然在文档列表中列出,而不是被弃用。

导入语句如下:

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

使用 o NGRX 的版本,如包 json 所示,如下所示:

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

还用谷歌搜索了这个问题,没有结果。只有将“forRoot”改为“provideStore”的结果,我已经使用了。

4

2 回答 2

3

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

  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,您可以在安装下的以下链接中看到这一点:https: //github.com/ngrx/store

于 2018-04-24T08:50:19.053 回答
0

您的代码还有其他问题。

错误没有说“类型 StoreModule 上不存在属性‘forFeature’”

它说“TYPEOF StoreModule 类型上不存在属性'forFeature'”(应该未定义)。

于 2018-04-23T15:47:40.230 回答