AngularNgRx组件存储.switchMap首先发出旧值
创始人
2024-10-28 18:00:41
0

该问题的解决方法是使用exhaustMap替代switchMap。exhaustMap等待前一个内部Observable完成后才会触发下一个内部Observable,并忽略中间的值。这确保了我们始终使用最新的值。

代码示例:

import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { exhaustMap, map } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { AppState } from './app.state';

@Component({
  selector: 'app-root',
  template: `
    

{{ title$ | async }}

`, }) export class AppComponent implements OnInit { title$: Observable; constructor(private store: Store) {} ngOnInit() { this.title$ = this.store.select('title').pipe( exhaustMap((title) => { return this.doSomethingAsync(title); }) ); } doSomethingAsync(value: string): Observable { return of(value).pipe( delay(1000), map((title) => { return `Hello ${title}!`; }) ); } }

相关内容

热门资讯

第三方辅助!hhpoker有没... 第三方辅助!hhpoker有没有外挂,德普之星透视辅助软件下载,竟然真的有挂(讲解有挂)1、德普之星...
2026版规律!we poke... 2026版规律!we poker免费辅助器,德扑之星透视辅助软件激活码,确实真的是有挂(有挂存在)1...
不少玩家反映!wepoker破... 不少玩家反映!wepoker破解是真的还是假的,德扑之星怎么开辅助,原来确实有挂(有挂细节)不少玩家...
2026版规律!约局吧开挂神器... 2026版规律!约局吧开挂神器是真的吗,德扑圈透视挂,总是是真的有挂(有挂规律)1、超多福利:超高返...
2026版技巧!约局吧游戏挂,... 2026版技巧!约局吧游戏挂,智星德州插件2024最新版,竟然真的是有挂(有挂辅助)1、用户打开应用...
代打辅助挂!wepoker辅助... 代打辅助挂!wepoker辅助真的假的,德扑之星私人局辅助器,一贯存在有挂(今日头条)1、德扑之星私...
现场直击!wepoker破解器... 现场直击!wepoker破解器有用吗,德扑圈透视,一直真的是有挂(有挂解密)1、德扑圈透视透视辅助软...
针对!wepoker永久免费脚... 针对!wepoker永久免费脚本,德普之星透视免费,好像是有挂(了解有挂)1、很好的工具软件,可以解...
无独有偶!pokemmo手机辅... 无独有偶!pokemmo手机辅助软件,德普之星app安卓版破解版,总是真的是有挂(讲解有挂)1、全新...
经核实!wepoker怎么设置... 经核实!wepoker怎么设置透视,德普辅助软件,竟然存在有挂(有挂秘笈)一、德普辅助软件游戏安装教...