在 Angular-13 的 typescript 中,我得到了以下代码:
ngOnInit(): void {
this.appSettingsService.getSettings()
.subscribe(settings => this.settings = settings,
() => null,
() => {
this.defaultSidebarColor = this.settings.defaultSidebarColor;
this.defaultBrandlogoColor = this.settings.defaultBrandlogoColor;
});
}
但是出现了错误,如下所示:
"the declaration was marked as deprecated" for .subscribe
我的 .subscribe 被划掉了。
如何解决这个问题?
提前谢谢您。
最佳答案
这里有完整的详细信息和示例:https://rxjs.dev/deprecations/subscribe-arguments
总结一下:签名 subscribe(next,error,complete) 已被弃用,转而使用“next”、“error”和“complete”中的一个或多个键传递对象。
在您的示例中,您可以这样重构:
.subscribe({
next:settings => this.settings = settings,
error:() => null,
complete:() => {
this.defaultSidebarColor = this.settings.defaultSidebarColor;
this.defaultBrandlogoColor = this.settings.defaultBrandlogoColor;
}
});
关于Angular - 如何在 ngOnInit() 中解析 .subscribe 的 "the declaration was marked as deprecated",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72717320/