I have been trying to implement sign in with Google in angular 2 in a separate login component. I am unable to implement it with the documentation available in Google https:
There is also another way to connect with google :
Add theses lines in the index.html :
and then here is a sample code to write on a component (or a service if you want) :
import {Component} from "@angular/core";
declare const gapi : any;
@Component({ ... })
export class ComponentClass {
constructor() {
gapi.load('auth2', function () {
gapi.auth2.init()
});
}
googleLogin() {
let googleAuth = gapi.auth2.getAuthInstance();
googleAuth.then(() => {
googleAuth.signIn({scope: 'profile email'}).then(googleUser => {
console.log(googleUser.getBasicProfile());
});
});
}
}