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; }) ); } }

相关内容

热门资讯

透视脚本!wepoker辅助透... 透视脚本!wepoker辅助透视软件,pokemmo辅助官网,2025新版(竟然真的是有挂)1、不需...
透视教程!wpk有脚本吗,we... 透视教程!wpk有脚本吗,we-poker辅助器,解密教程(原来真的是有挂)是一款可以让一直输的玩家...
透视智能ai!wepoker脚... 透视智能ai!wepoker脚本,hh poker透视器下载,2025新版教程(竟然是有挂)关于we...
透视工具!hhpoker透视脚... 透视工具!hhpoker透视脚本安卓,hhpoker免费辅助器,介绍教程(原先有挂);(需添加指定Q...
透视了解!wpk辅助软件多少钱... 透视了解!wpk辅助软件多少钱一个,来玩德州破解器,2025新版技巧(竟然真的有挂);科技详细教程Q...
透视挂透视!wpk透视脚本视频... 透视挂透视!wpk透视脚本视频,wejoker辅助器怎么卖,安装教程(一直真的有挂);原来确实真的有...
透视玄学!wepoker透视脚... 透视玄学!wepoker透视脚本下载,pokemomo辅助工具,切实教程(真是是真的有挂);超受欢迎...
透视私人局!红龙poker有辅... 透视私人局!红龙poker有辅助吗,德普之星辅助工具如何设置,技巧教程(原本有挂);玩家在红龙pok...
透视软件!红龙poker作弊指... WePoker透视辅助版本稳定性对比与推荐‌:透视软件!红龙poker作弊指令,wepoker透视最...
透视好友房!hhpoker辅助... 透视好友房!hhpoker辅助器,wepoker私人局可以透视,总结教程(一直真的是有挂);hhpo...