How to implement SignIn with Google in Angular 2 using Typescript

前端 未结 7 971
梦毁少年i
梦毁少年i 2020-11-28 04:11

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:

7条回答
  •  情话喂你
    2020-11-28 04:39

    pretty much none of this worked for me because I want the google button made by Google. @mathhew eon's code worked but that does not use their button.

    so I threw the google data-success function on the window and it works PERFECT! It also has the added advantage of if the user is already logged in it will auto call the googleLogin function.

    html

    In your index.html put this in the head:

    
    
    
    

    then in your ngOnInit

    ngOnInit() {
        (window as any).googleLogin = this.googleLogin
    }
    public googleLogin(userInfo) {
        console.log(userInfo)
    }
    

提交回复
热议问题