NgRx store.select无法使用管道



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

这里有一些代码:

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

上面的代码完美地工作;但下面的方法没有,订阅方法也没有被调用:

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

如果我在管道内使用flatMap()方法,也会出现同样的问题。似乎不知道出了什么问题。这是我推送给Stacklitz 的代码链接

上述代码在component2.component.ts文件中请帮忙。

take(1(正在工作,但由您调度操作之前发生的状态更改触发

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

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

最新更新