NgRx store.select不适用于管道

时间:2019-11-14 19:18:35

标签: angular rxjs ngrx-store

我正在尝试从store中进行选择,并将pipetake()flatMap()函数一起使用。

以下是一些代码:

 this.userState.subscribe(item => console.log("without pipe"));

上面的代码非常有效;但是下面的那个没有,subscribe方法没有被调用:

this.userState.pipe(take(1)).subscribe(item => console.log("with take and flatmap"));

如果我在管道内部使用flatMap()方法,则会出现同样的问题。似乎无法找出问题所在。 这是我推送到Stackblitz

的代码的链接

上面的代码在component2.component.ts文件中 请帮助。

1 个答案:

答案 0 :(得分:0)

take(1)正常运行,但是由您在分派动作之前发生的状态更改触发

管道需要返回一些东西。试试看:

this.userState.pipe(map(data => data)).subscribe(item => console.log("with take and flatmap"));