The Observable is not accepting Catch

Asked

Viewed 123 times

0

Note the figure below; inserir a descrição da imagem aqui

Why is the Observable not accepting the catch?

2 answers

1


To use the 'Catch' operator, you need to import it from the rxjs library in this way:

import 'rxjs/add/operator/catch';

So you can use it.

0

Since Observable is asynchronous, Try/catch does not work. You should set an error callback as the example below angular documentation:

myObservable.subscribe({
  next(num) { console.log('Next num: ' + num)},
  error(err) { console.log('Received an errror: ' + err)}
});
  • 1

    i put as correct, but really solved my problem by putting this import import 'rxjs/add/Operator/catch';

Browser other questions tagged

You are not signed in. Login or sign up in order to post.