Reputation: 1841
I have an angular 2 project where my login either returns an object with data or an object with an error message if no user exists.
Here is my code:
userLogin(f){
this.auth.login(f.value)
.subscribe(res => {
console.log('Response: ' + res.json());
//this.navCtrl.push('TabsPage')
}, err => {
console.log('An error occured.')
})
}
For some reason, I'm getting an error that says res.json() is not a function.
Even though I can see in the console the following is returned when there is not user:
{"success":false,"msg":"Authentication failed. User not found."}
So why would I get the error:
ion-dev.js?v=3.0.1:156 ERROR TypeError: res.json is not a function
Thanks!
Upvotes: 2
Views: 35
Reputation: 222582
You no longer need to call this function yourself because HttpClient.get()
applies res.json() automatically and returns Observable<HttpResponse<string>>
.
Upvotes: 2