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

在使用switchMap时,使用pipe操作符结合startWith运算符将初始值传入pipe中,这样一来switchMap就会在发出最新值前首先发出初始值。 代码示例:

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

@Component({ selector: 'app-my-component', templateUrl: './my-component.component.html', styleUrls: ['./my-component.component.css'] }) export class MyComponent implements OnInit { myValue$: Observable;

constructor(private store: Store) {}

ngOnInit() { this.myValue$ = this.store.select('myValue').pipe( startWith('initialValue'), switchMap(newVal => { // do something with newVal return newVal; }) ); } }

相关内容

热门资讯

WPK模拟器!aapoker技... WPK模拟器!aapoker技巧开挂ai,德州局脚本,确实有ai开挂演示1、很好的工具软件,可以解锁...
WPK插件!aapoker插件... WPK插件!aapoker插件透视ai,wpk有作弊吗,果然真的是有ai透视模块1、许多玩家不知道w...
WPK购买!微扑克方法辅助器a... WPK购买!微扑克方法辅助器ai,德普之星怎么设置埋牌,一直是有ai辅助器方式1、玩家可以在德普之星...
WPK控制牌!智星菠萝德州插件... WPK控制牌!智星菠萝德州插件辅助ai,aapoker插件下载,切实真的是有ai辅助攻略1、打开软件...
WPK辅助器!德扑之星攻略辅助... WPK辅助器!德扑之星攻略辅助器ai,wpk辅助是什么,总是存在有ai辅助器步骤1、操作简单,无需w...
WPK靠谱!德扑之星方法辅助a... WPK靠谱!德扑之星方法辅助ai,哈糖大菠萝有没有挂,果然真的有ai辅助积累1、哈糖大菠萝有没有挂破...
WPK下载!wpk插件透视挂a... WPK下载!wpk插件透视挂ai,AApoker控制牌,好像真的是有ai透视挂教程书1、不需要AI权...
WPK私人局!微扑克脚本透视挂... WPK私人局!微扑克脚本透视挂ai,wpk有辅助器吗,本来有ai透视挂指南运wpk有辅助器吗辅助工具...
WPK方法!红龙扑克脚本透视a... WPK方法!红龙扑克脚本透视ai,德普之星辅助器怎么用,真是有ai透视模块进入游戏-大厅左侧-新手福...
WPK私人局!红龙PoKer软... WPK私人局!红龙PoKer软件透视挂ai,AApoker俱乐部,其实是真的有ai透视挂步骤1、首先...