[英]“subscribe()” is deprecated when using “of(false)”
我正在嘗試使用of
但我的編輯說它已被棄用。 我怎樣才能讓這個工作使用of
?
public save(): Observable<ISaveResult> | Observable<boolean> {
if (this.item) {
return this.databaseService.save(this.userId, this.item)
}
return of(false)
}
public componentSave() {
const sub = this.userService
.save()
.subscribe(val => {
// This callback shows the below error in the editor
})
}
當我使用它時,我的編輯器中出現以下錯誤:
@deprecated — Use an observer instead of a complete callback
'(next: null, error: (error: any) => void, complete: () => void): Subscription' is deprecated
Expected 2-3 arguments, but got 1.
沒關系,我想我找到了問題所在。 將保存 function 的返回類型從
public save(): Observable<ISaveResult> | Observable<boolean>
至
public save(): Observable<ISaveResult | boolean>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.