rxjs-observables

RxJS shareReplay() does not emit updated value

情到浓时终转凉″ 提交于 2020-08-10 19:19:47
问题 I have a user service which allows login, logout and maintains data about the currently logged in user: user$ = this.http.get<User>('/api/user') .pipe( shareReplay(1), ); I am using shareReplay(1) because I do not want the webservice to be called several times. On one of the components, I have this (for simplicity), but I have several other things I want to do if a user is logged in: <div *ngIf="isUserLoggedIn$ | async">Logout</div> isUserLoggedIn$ = this.userService.user$ .pipe( map(user =>

Angular template binding with Observable async pipe issue [duplicate]

假如想象 提交于 2020-05-28 06:53:08
问题 This question already has an answer here : Template binding with function return Observable and async pipe (1 answer) Closed 13 days ago . Note I have created a simplified version of this question at Template binding with function return Observable and async pipe Template: <div *ngIf="entity?.ext.insuredDetails.insuredType$() | async as insuredType"> {{insuredType}} </div> insuredType$ definition: @NeedsElement(sp(115621),ap(116215)) insuredType$(): Observable<string> { return empty(); }

Template binding with function return Observable and async pipe

蓝咒 提交于 2020-05-24 03:38:49
问题 Note this is simplified question of Angular template binding with Observable async pipe issue template: <div>{{foo()$ | async}}</div> source code: import { Component } from "@angular/core"; import { BehaviorSubject, of, Observable } from "rxjs"; import { tap, delay, map, switchMap, concatMap } from "rxjs/operators"; @Component({ selector: "my-app", templateUrl: "./app.component.html", styleUrls: ["./app.component.css"] }) export class AppComponent { private index = 0; foo$(): Observable<any>