How to pass object from Provider to Component and shows these Data to view?

#1

My Login.ts file

logForm = function()
{

this.loginProvider.login(this.user);

}

And Provider method:

login(user) {
let data: object;
let dt = “grant_type=password&username=” + user.username + “&password=” + user.password;

let headers = {
  'Content-Type': 'application/x-www-form-urlencoded'
};

this.http.post(this.baseUrl, dt, { headers }).subscribe(
  res => {
    data = res;
    console.log(data);
    return data ;
  },
  err => {
    alert("Error!");
  });

}

#2

One heuristic I use is “never subscribe in providers”. If you follow that, and declare an explicit return type for login(), you will lead yourself towards understanding and resolution.