我想獲得最新的價值。有2個API。一個是 updatePhoneNo,另一個是 getPhoneValue。在我呼叫 updatePhoneNo API 之后,加載了 getPhoneValue 并更新了最新值。但是html頁面沒有更新。如何解決?
TS:
projects$: Observable<CustDetaill>;
ngOnInit() {
this.projects$ = this.custService.getPhoneValue(this.custno);
}
update(){
this.custService.updatePhoneNo(this.custphoneno).subscribe(
res => {
this.projects$.next(this.custphoneno);
});
}
HTML
{{(projects$ |async)?.phoneNo}}
uj5u.com熱心網友回復:
我認為您應該將其視為可觀察的,并像這樣從 typeScript 中使用它
this.projects$.next(newValue);
更新
我看到了您的編輯.. 好的,首先您需要更改專案型別$
projects$: BehaviorSubject<CustDetaill>;
并通過“下一個”關鍵作業使其具有價值我為你寫了一個例子..希望它可以幫助
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/517875.html
