【发布时间】:2021-03-12 23:12:43
【问题描述】:
我正在尝试使用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.
【问题讨论】:
-
我确实怀疑您正在从旧的 rxjs 模块路径导入某些内容,但您确实需要提供一个示例 stackoverflow.com/help/minimal-reproducible-example
-
我正在使用
Import {of} from 'rxjs'
标签: javascript angular typescript rxjs