问题是
this.crumbs$
已传递给
withLatestFrom(this.crumbs$)
,但只有在构造函数中赋值后才能定义它。
您可以使用
defer
:
import { defer } from "rxjs/observable/defer";
...
.withLatestFrom(defer(() => this.crumbs$))
或者使用函数声明效果:
@Effect()
breadcrumbs$(): Observable<ChangeBreadcrumbsCompleteAction> {
return this.actions$
.ofType(BreadcrumbActionTypes.ChangeBreadcrumbs)
.withLatestFrom(this.crumbs$)
.map((result: any) => {
let action: ChangeBreadcrumbsAction, crumbs: any[];
[action, crumbs] = result;
/* make a copy of the existing crumbs. */
/* this code is still being worked on, hence the hardcoded index */
const newCrumbs = crumbs.slice(0);
if (crumbs.length > 0) {
newCrumbs[1] = { ...newCrumbs[1], displayName: action.name }
}
return new ChangeBreadcrumbsCompleteAction(newCrumbs);
});