I believe you are returning a Promise , then the .then()
method should be used in the request, the .subscribe()
method is for Observables .
Service
function teste(user) {
return this.http.post('api/home', user);
}
For Promises
ok(user){
this.loginServ.teste(user)
.then(success);
function success(response){
console.log(response);
}
}
For Observables
ok(user){
this.loginServ.teste(user)
.subscribe(data => {
console.log(data);
});
}
Promises vs Observables
Promises - Promises deal with sigular events when an asynchronous operation succeeds or fails.
Observable - An Observable is like a Stream and allows you to pass 0 or more events when the response is returned and also call functions or callbacks for those events. >