You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular5项目使用angular2-social-auth报错:socialSignIn不是函数

问题排查与解决方案

嘿,我一眼就揪出了导致你报错的核心问题!你遇到的TypeError: _co.socialSignIn is not a function,本质是HTML模板里调用的方法名和组件类里定义的方法名不匹配。


直接原因:方法名不一致

你在组件类(component.ts)里定义的登录方法叫signIn,但在HTML模板里却写了socialSignIn('facebook')——组件里根本没这个方法,Angular找不到它,自然就抛出错误了。

第一步:修正HTML模板的方法名

把模板里的socialSignIn全部改成signIn,就能正确绑定到组件的方法上了:

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

第二步:优化模块配置(可选但推荐)

另外,我注意到你在AppModule外部调用Angular2SocialLoginModule.loadProvidersScripts(providers),这种写法在部分场景下可能出现加载顺序问题。更规范的做法是用模块的forRoot方法传入配置:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { Angular2SocialLoginModule } from "angular2-social-auth";

let providers = {
  "facebook": {
    "clientId": "MyGeneratedCode",
    "apiVersion": "v2.11"
  }
};

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    Angular2SocialLoginModule.forRoot(providers) // 改用forRoot传入配置
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

// 移除这一行:Angular2SocialLoginModule.loadProvidersScripts(providers);

最后检查项

做完上面的修改后,再确认两个细节:

  • 你的Facebook clientId是正确生成且已在Facebook开发者平台配置好授权域名的;
  • apiVersion(v2.11)是否符合Facebook当前的API支持要求(如果版本过旧可能会有兼容性问题,建议用最新的稳定版)。

这样修改后,点击Facebook登录按钮应该就能正常触发登录流程啦~

内容的提问来源于stack exchange,提问作者user9192087

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:29:40