获取错误ngrx Store不是rxjs的实例Observable

时间:2018-10-10 21:59:52

标签: angular rxjs ngrx ngrx-store rxjs6

我的棱角项目中不断出现错误You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.。 基本上,我正在尝试访问存储状态值,如下所示:

@Effect()
getHoles$ = this.actions$.pipe(
  ofType<GetTreeHoles>(HolesActions.GetTreeHoles),
  withLatestFrom(this.store.pipe(select(getLastDocumentSnapshot))),
  ...

但是,当代码尝试解决下面的可观察对象时,它将引发错误。

this.store.pipe(select(getLastDocumentSnapshot))

我尝试执行代码,并发现代码在文件rxjs的subscriptionTo.js中失败:

if (result instanceof Observable_1.Observable) {

此if语句返回false。由于存储扩展了Observable,因此此if语句应返回true。因此,代码转到下面的else语句并引发错误:

else {
    var value = isObject_1.isObject(result) ? 'an invalid object' : "'" + result + "'";
    var msg = "You provided " + value + " where a stream was expected."
        + ' You can provide an Observable, Promise, Array, or Iterable.';
    throw new TypeError(msg);
}

我将代码更改为简单的东西:

@Effect()
getHoles$ = this.actions$.pipe(
  ofType<GetTreeHoles>(HolesActions.GetTreeHoles),
  withLatestFrom(of(123)),
  ...

但是,它仍然会返回相同的错误,并且由于of(123)而失败,这对我来说没有意义。

我用withLatestFrom删除了行,效果很好。

我仔细检查过,我正确地导入了LatestFrom。

import { catchError, switchMap, withLatestFrom } from 'rxjs/internal/operators';

我的版本:

"@angular/animations": "^6.1.10",
"@angular/cdk": "^6.4.7",
"@angular/common": "^6.1.10",
"@angular/compiler": "^6.1.10",
"@angular/core": "^6.1.10",
"@angular/forms": "^6.1.10",
"@angular/http": "^6.1.10",
"@angular/material": "^6.4.7",
"@angular/platform-browser": "^6.1.10",
"@angular/platform-browser-dynamic": "^6.1.10",
"@angular/router": "^6.1.10",
"@ngrx/effects": "^6.1.0",
"@ngrx/router-store": "^6.1.0",
"@ngrx/store": "^6.1.0",
"@ngx-translate/core": "^10.0.2",
"@ngx-translate/http-loader": "^3.0.1",
"core-js": "^2.5.4",
"firebase": "^5.5.3",
"rxjs": "~6.2.0",

此错误使我发疯。请帮我解决。谢谢。

0 个答案:

没有答案