Observable .catch is not a function

I get this very nasty error when running my code from unix environment. This works fine when I run the code locally through ng serve, but when I deploy the code on my server, this error stops the execution of all programs:

ERROR TypeError: this.http.get(...).catch is not a function

The Google results indicated that I should import the rxjs namespaces directly from their location, and not through the rxjs / Rx package, but I get this error independently. Other results indicate that I may have missed importing rxjs statements, but they are definitely included in my case.

I even checked the included source maps using DevTools, and the operators are included in the browser.

Can someone tell me why I am getting this error? I am using rxjs: ^ 5.5.2

This is my code.

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';

@Injectable()
export class MyService {
  constructor(private http: HttpClient) {}

  all(): Observable<any> {
    return this.http.get<any>('url')
      .catch(err => this.handleError(err));
  }
  handleError(error) {
    return Observable.throw(error);
  }
}

@Jota.Toledo , , :

this.myService.all().subscribe(
  result => {
    this.isLoading = false;
    if (result) {
      this.clients = result;
    }
  },
  error => this.isLoading = false
);

, , " catch - "?

+4
1

rxjs 5.5.2 , lettable, catchError. operators, : import { catchError } from 'rxjs/operators/catchError';. , , observable observable/of.

import { catchError } from 'rxjs/operators/catchError';
import { map } from 'rxjs/operators/map';

all(): Observable<any> {
  return this.http.get<any>('url')
    .pipe(
        map(() => //do stuff),
        catchError((error: Error) => {
         //
        })
    )
}

lettable .

+5

Source: https://habr.com/ru/post/1689615/


All Articles