簡體   English   中英

NgRx store.select 不適用於 pipe

[英]NgRx store.select does not working with pipe

我正在嘗試從store購買 select 並將pipetake()flatMap()函數一起使用。

這是一些代碼:

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

上面的代碼完美運行; 但是下面的那個沒有,並且沒有調用 subscribe 方法:

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

如果我在 pipe 中使用flatMap()方法,也會出現同樣的問題。 似乎無法弄清楚出了什么問題。 這是我推送到Stackblitz的代碼的鏈接

以上代碼在component2.component.ts文件中,請幫忙。

take(1) 正在工作,但由在您發送操作之前發生的 state 更改觸發

Pipe 需要返回一些東西。 試試這個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM