[英]Typescript Deprecation warning
I am using this code for login but subscribe shows depricated.我正在使用此代码进行登录,但订阅显示已被贬低。 I am new to typescript, so can anyone help me out
我是 typescript 的新手,所以谁能帮帮我
doLogin()
{
this.userService.doLogin(this.loginForm.value).subscribe(
result =>
{
console.log(result);
localStorage.setItem('userData', JSON.stringify(result));
this.router.navigate(['/list-user']);
this.toastr.success('Success', 'Logged In Successfully');
},
(error) =>
{
console.log(error);
this.toastr.error('Failed', 'Invalid Credentials');
});
}
this works in an other project I've worked on but shows depricated here and I'm getting this error:这在我从事的另一个项目中有效,但在这里显示被贬低,我收到了这个错误:
@deprecated — Instead of passing separate callback arguments, use an observer argument. @deprecated — 不要传递单独的回调 arguments,而是使用观察者参数。 Signatures taking separate callback arguments will be removed in v8.
采用单独回调 arguments 的签名将在 v8 中删除。 Details: https://rxjs.dev/deprecations/subscribe-arguments
详细信息: https://rxjs.dev/deprecations/subscribe-arguments
'(next?: ((value: Object) => void) | null | undefined, error?: ((error: any) => void) | null | undefined, complete?: (() => void) | null | undefined): Subscription' is deprecated.ts(6385) Observable.d.ts(55, 9): The declaration was marked as deprecated here. '(next?: ((value: Object) => void) | null | undefined, error?: ((error: any) => void) | null | undefined, complete?: (() => void) | Z37B978EZADA1 | undefined): Subscription' is deprecated.ts(6385) Observable.d.ts(55, 9): 声明在此处被标记为已弃用。
As per the link根据链接
import { of } from 'rxjs';
// recommended
of([1,2,3]).subscribe((v) =>
console.info(v));
// also recommended
of([1,2,3]).subscribe({
next: (v) => console.log(v),
error: (e) => console.error(e),
complete: () =>
console.info('complete')
})
You will no longer need to pass more than one callback.您将不再需要传递多个回调。 If needed you can pass in an observable object containing the callbacks.
如果需要,您可以传入包含回调的可观察 object。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.