I have the following scenario:
api.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
const baseUrl: string = 'https://example.com/api/v1';
@Injectable({
providedIn: 'root'
})
export class ApiService {
constructor(private http: HttpClient) { }
getSingleUser(mail: string) {
console.log('Getting info from:');
var url: string = baseUrl + '/users/' + mail;
console.log(url);
return this.http.get(url);
}
}
login.component.ts
import { Component, OnInit } from "@angular/core";
import { Router } from "@angular/router";
import { ApiService } from 'app/api.service';
@Component({
selector: "login-cmp",
moduleId: module.id,
templateUrl: "login.component.html"
})
export class LoginComponent implements OnInit {
private userProfile: any = [];
private email: string = '[email protected]';
constructor(private router: Router,
private apiService: ApiService) {}
ngOnInit() { }
signIn(provider: String): void {
console.log('Starting http for ' + this.email);
this.apiService.getSingleUser(this.email)
.subscribe(data => {
console.log('entered subscribe');
console.log(data);
});
console.log('Finished getting data.');
}
});
}
}
And this is the output on my console:
Starting http for [email protected]
Getting info from:
https://example.com/api/v1/users/[email protected]
Finished getting data.
What I can see in the log is that the method getSingleUser is being called (messages 2 and 3 are generated by the method), but the commands inside the subscribe block are not being executed and I do not understand why.
/api/v1/users/[email protected]will be enough. 2. Did you check DevTools? Was the request actually send? And which HTTP status code does it have? In case of an error yoursubscribeblock won't be called