【问题标题】:How to make angular-social-auth using angular如何使用 angular 制作 angular-social-auth
【发布时间】:2018-07-05 22:16:42
【问题描述】:

我是 angular2-social-auth,在 angular 5 的项目中,但它给了我一个错误代码:

模块.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>   

我按照文档告诉我的做了,有人可以帮忙吗? 当我点击 facebook 按钮时,它给了我这个错误:

TypeError: _co.socialSignIn 不是函数 堆栈跟踪: View_AppComponent_0/

【问题讨论】:

    标签: angular google-authentication facebook-authentication


    【解决方案1】:

    您尝试在您的 html 中调用一个名为“socialSignIn”的函数,但是我在您的代码中没有看到此函数。 所以错误信息很清楚:socialSignIn is not a function

    尝试致电signIn('facebook')

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-19
      • 2017-02-28
      • 1970-01-01
      相关资源
      最近更新 更多