1

Below is my component method

if (id !== undefined && id != null && id !== 0) {
              this.dataService.getTransactionById(id).subscribe(
                
                (tr: ITransactionResponse) => {
                if (tr != null) {
                   this.transaction = tr;
                }
                else {
                  this.router.navigate(['/']);
                }
              });

Deprecated: But it showing as deprecated in my angular project. Please let me know what could by I change this method?

EDIT :

I Have changed my method to below code (RXJS 6)

 this.tranService.getTransactionById(id).subscribe({
            next: (result: any)  => {            
              this.transaction = result;
            },
            error: (error:any) => {
               this.router.navigate(['/transaction/transaction-list']);
            },
            complete: () => {
              //console.log('complete');
            }
          }); 

But Still showing Deprecated

Deprecated Infi

Glen
  • 321
  • 4
  • 15

1 Answers1

1

i think you are fine, just one of all possible overrides is deprecated. See this issue for a deeper discussion: Subscribe is deprecated: Use an observer instead of an error callback

Also for your initial If-Clause, i think you could change it to this with the same result:

if(!id) { .... }
Roundtrip
  • 73
  • 10
  • How to change as per my reuirement?am just confused? – Glen Jun 16 '21 at 05:34
  • I think you can just ignore the deprecation warning. This is a tooling issue of Visual Studio Code, and does not impact your code in any way. – Roundtrip Jun 16 '21 at 06:14