我正在尝试从store
中进行选择,并将pipe
与take()
和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
文件中
请帮助。
答案 0 :(得分:0)
take(1)正常运行,但是由您在分派动作之前发生的状态更改触发
管道需要返回一些东西。试试看:
this.userState.pipe(map(data => data)).subscribe(item => console.log("with take and flatmap"));