Sreenath Reddy
Sreenath Reddy

Reputation: 11

How to write success and error functions in angular 6

How to write success and error functions in angular 6

i have tried this

.success(data =>
{

})

.error(data =>
{

})

Upvotes: 0

Views: 141

Answers (2)

Sagar Chaudhary
Sagar Chaudhary

Reputation: 1403

I think this one is better:

               .subscribe(data =>{
                    console.log(data);
                }, error => {
                    console.log(error);
                });

Upvotes: 2

Saurabh Siddhu
Saurabh Siddhu

Reputation: 158

The question is not clear but I am assuming that you are asking about observables. This can be done in following manner:

myObservable.subscribe(
  x => console.log('Observer got a next value: ' + x),
  err => console.error('Observer got an error: ' + err),
  () => console.log('Observer got a complete notification')
);

Upvotes: 1

Related Questions