【问题标题】:Cannot find rxjs select operator used by ngrx store.select找不到 ngrx store.select 使用的 rxjs 选择运算符
【发布时间】:2019-04-29 14:46:50
【问题描述】:

无法从 rxjs 库中找到选择运算符。

据我了解和解释here,当我们调用store.select 方法时,ngrx 商店使用来自 rxjs 库的选择运算符。它目前的工作方式是如果我将整个 rxjs 库删除:

import 'rxjs/Rx';

但这会导入整个 rxjs 运算符,我只想导入我需要的运算符。

如果我排除 rxjs/Rx 导入,则会出现此错误:

TypeError: this.store.select(...).first is not a function

我还在 npm rxjs 包目录中进行了全局搜索,该文件夹中没有任何带有 select 的文件。真的很混乱。

【问题讨论】:

  • select 运算符是@ngrx/core 的一部分并且是bound to the Store。正如马丁在回答中指出的那样,您的错误与 first 运算符有关。
  • 谢谢@cartant,我错过了。

标签: rxjs ngrx angular4


【解决方案1】:

如果您不想导入整个库,您可以只选择您想要的操作符/Observables,例如:

import 'rxjs/add/operator/first';

您可以在此处查看完整列表:https://github.com/ReactiveX/rxjs/tree/master/src/add/operator

【讨论】:

  • 谢谢马丁。工作。
【解决方案2】:

请也试试

npm un --save rxjs
npm un --save rxjs-compat

npm i --save rxjs@6.2.2
npm i --save rxjs-compat@6.2.2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-03
    • 1970-01-01
    • 1970-01-01
    • 2019-01-27
    • 1970-01-01
    • 2017-07-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多