In the typescript of Angular-13, I got this code:
ngOnInit(): void {
this.appSettingsService.getSettings()
.subscribe(settings => this.settings = settings,
() => null,
() => {
this.defaultSidebarColor = this.settings.defaultSidebarColor;
this.defaultBrandlogoColor = this.settings.defaultBrandlogoColor;
});
}
But an error came up as shown here:
"the declaration was marked as deprecated" for .subscribe
And I got .subscribe crossed.
How do I get this sorted out?
Thank you in advance.
CodePudding user response:
Here you have the full details and examples: https://rxjs.dev/deprecations/subscribe-arguments
To summarize: the signature subscribe(next,error,complete) is getting deprecated in favor of passing an object with one or more of the keys 'next', 'error' and 'complete'.
In your example, you'd refactor this way:
.subscribe({
next:settings => this.settings = settings,
error:() => null,
complete:() => {
this.defaultSidebarColor = this.settings.defaultSidebarColor;
this.defaultBrandlogoColor = this.settings.defaultBrandlogoColor;
}
});