[英]Angular - how can I update a field in my BehaviorSubject store value in a function without calling getValue
[英]How can I get my Angular BehaviorSubject to fire?
我有以下設置,但它不起作用。 我從來沒有看到警報彈出窗口。
// this is in ngOnInit
this.getBackDate$.subscribe();
//this.$spService.clientProfile$ is as follows:
public clientProfile$: Observable<ClientProfile | null> = this.client$.pipe(
tap(()=> this.clientProfileIsLoading$.next(true)),
switchMap( (client) => {
if (!client) {
return of<ClientProfile>(null);
}
return this.$http.get<ClientProfile>(ApiDomain.supervisionPlan, `/v1/Client/ClientProfile?clientIdToken=${client.entityIdToken}`)
}),
tap(() => this.clientProfileIsLoading$.next(false))
);
...
getSelectedClient$ = new BehaviorSubject<ClientProfile>(null);
getBackDate$ = this.getSelectedClient$.pipe(
withLatestFrom(this.$spService.clientProfile$),
tap(([client]) => {
alert(client.caseStart)
this.maxBackdate = client.caseStart;
})
);
編輯:
如果我改變它,它可以工作,但我不想使用 combineLatest,因為我沒有組合任何東西。
getBackDate$ = combineLatest([this.$spService.clientProfile$]).pipe(
tap(([client]) => {
alert(client.caseStart)
this.maxBackdate = client.caseStart;
})
);
如果您在這里查看,您會發現兩個可觀察對象都需要發出一個值。 否則什么都不會發生。 因此,您可以執行以下操作:
clientProfileReplay$ = this.$spService.clientProfile$.pipe(
shareReplay({ bufferSize: 1, refCount: true })
);
然后在 withLatestFrom() 中使用 clientProfileReplay$。
看起來像你有一個異步錯誤
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.