简体   繁体   中英

How to make angular-social-auth using angular

I'm angular2-social-auth, in project with angular 5, but it gives me an error heres the code :

Module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';


import { AppComponent } from './app.component';
import { Angular2SocialLoginModule } from "angular2-social-auth";

let providers = {
  /* "google": {
  "clientId": "GOOGLE_CLIENT_ID"
},
"linkedin": {
  "clientId": "LINKEDIN_CLIENT_ID"
 },*/
"facebook": {
   "clientId": "MyGeneratedCode",
   "apiVersion": "v2.11" //like v2.4
 }

};

@NgModule({
 declarations: [
  AppComponent
   ],
imports: [
 BrowserModule,
  Angular2SocialLoginModule
],
 providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Angular2SocialLoginModule.loadProvidersScripts(providers);

component.ts :

import { Component, OnDestroy } from '@angular/core';
import { AuthService } from "angular2-social-auth";

@Component({
 selector: 'app-root',
 templateUrl: './app.component.html',
 styleUrls: ['./app.component.css']
 })
 export class AppComponent  implements OnDestroy {

 title = 'app';

  constructor(public _auth: AuthService){ }

 signIn(provider){
 this._auth.login(provider).subscribe(
   (data) => {
               console.log(data);
               //user data
               //first_name, last_name, image, uid, provider, email, token     (returns  accessToken for Facebook and Google no token for linkedIn)
             }
 )

}

 logout(){
   this._auth.logout().subscribe(
   (data)=>{
     //return a boolean value.
    }
  )
 }

}

html :

<h1>
 Sign in
</h1>

<button (click)="socialSignIn('facebook')">Sign in with Facebook</button>
<button (click)="socialSignIn('google')">Signin in with Google</button>   

I did just what the documentation told me, can any one help please? when i clic the facebook button it gives me this error :

TypeError: _co.socialSignIn is not a function Stack trace: View_AppComponent_0/<@ng:///AppModule/AppComponent.ngfactory.js:14:19 handleEvent@webpack-internal:///../../../core/esm5/core.js:13745:115

You try calling a function called "socialSignIn" in your html, however i don't see this function in your code. So error message is clear : socialSignIn is not a function

Try call signIn('facebook') instead

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM