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有透视指南!aapoke... WPK有透视指南!aapoker辅助插件工具,德州微扑克其实存在有透视挂攻略1、进入到aapoker...
WPK安卓学习!wpk辅助工具... WPK安卓学习!wpk辅助工具,德州微扑克真是真的有辅助攻略WPK安卓学习!wpk辅助工具,德州微扑...
WPK作弊学习!wejoker... 您好,wejoker辅助脚本这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】...
WPK有透视指南!黑侠破解we... WPK有透视指南!黑侠破解wepoker,德州微扑克真是存在有透视挂攻略1、点击下载安装,黑侠破解w...
WPK靠谱经验!wepoker... WPK靠谱经验!wepoker开脚本视频,德州微扑克果然真的有透视攻略1、不需要AI权限,帮助你快速...
WPK脚本攻略!wepoker... WPK脚本攻略!wepoker有辅助工具吗,德州微扑克切实存在有开挂技巧wepoker有辅助工具吗透...
WPK靠谱学习!wepoker... WPK靠谱学习!wepoker脚本下载,德州微扑克其实有透视挂工具在进入wepoker脚本下载软件靠...
WPK官网绝活!wepoker... WPK官网绝活!wepoker作弊辅助,德州微扑克本来是有开挂appWPK官网绝活!wepoker作...
WPK俱乐部模板!wepoke... WPK俱乐部模板!wepoker透视脚本是什么,德州微扑克其实真的是有透视技巧1、wepoker透视...
WPK透视版模板!wepoke... WPK透视版模板!wepoker买脚本靠谱吗,德州微扑克切实真的有辅助器插件1、点击下载安装,wep...