I'm a bit new to Angular (7). I'm trying to retrieve the status code when I do an HTTP request. Here's the code I use in a service :
checkIfSymbolExists() {
return this.http.get(this.url, { observe: 'response' })
.subscribe(response => {
return response.status;
});
}
And I use the returned value in a method in one of my components like this :
onSubmit() {
console.log(this.stocks.checkIfSymbolExists());
}
I was expecting a number to be returned, but instead I have an object :
Subscriber {closed: false, _parent: null, _parents: null, _subscriptions: Array(1), syncErrorValue: null, …}
closed: true
destination: SafeSubscriber {closed: true, _parent: null, _parents: null, _subscriptions: null, syncErrorValue: null, …}
isStopped: true
syncErrorThrowable: true
syncErrorThrown: false
syncErrorValue: null
_parent: null
_parentSubscription: null
_parents: null
_subscriptions: null
__proto__: Subscription
When, instead of simply returning response.status I do a console.log of it, I do get the 200 status code as expected (a number, and not an object).
Any ideas why it's not the same behavior when returning the value of response.status as shown here ? Thanks.