angular - 不支持调用 Angular2SocialLoginModule 函数调用

标签 angular angular2-routing angular2-template angular2-services

我是 Angular js2 的新手。目前我正在使用一个 web 应用程序,它使用 angular2 作为前端。在此应用程序中,我使用 angular2-social-login 进行身份验证。但是当我运行 npm start 时,出现以下错误

ERROR in Error encountered resolving symbol values statically. Calling function 'Angular2SocialLoginModule', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppModule in /var/www/html/ngtest/src/app/app.module.ts, resolving symbol AppModule in /var/www/html/ngtest/src/app/app.module.ts

google了一下,有人说是因为在项目中使用了angular cli。但是我卸载了angular cli,问题仍然存在。 有没有人知道如何解决这个问题?

我的 app.module.ts 代码如下

import { Angular2SocialLoginModule } from "angular2-social-login";
let providers = {    

 "facebook": {
  "clientId": "xxxxxxxxxxxxx",
  "apiVersion": "v2.8"
}, 
 "linkedin": {
  "clientId": "xxxxxxxxxxx"
}, 
"google": {
  "clientId": "xxxxxxxxxx"
}

};
@NgModule({
 imports: [
     Angular2SocialLoginModule.initWithProviders(providers),
 ],
})
export class AppModule { }

我在header.component.ts中调用了这个模块,请看header.component.ts文件

import { AuthService } from "angular2-social-login";
@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.css'],
providers: [Modal]
})
export class HeaderComponent implements OnInit {
constructor(public _auth: AuthService){ }

 signIn(provider){
 this.sub = this._auth.login(provider).subscribe(
 (data) => {
console.log(data);
   }
 )}
logout(){
this._auth.logout().subscribe(
(data)=>{


//return a boolean value.
}
)}
}

以上是我的代码,请看一下。如果需要更多详细信息,请评论

最佳答案

更新

在 angular2-social-login v.3.0.0 中你可以这样写:

@NgModule({
  ...
  imports: [ 
     Angular2SocialLoginModule
  ]
})
export class AppModule { 
  constructor(){}
}

Angular2SocialLoginModule.loadProvidersScripts(providers);

旧版本

移除

imports: [
  Angular2SocialLoginModule.initWithProviders(providers),
],

然后试试这个:

import { Angular2SocialLoginModule, AuthService } from "angular2-social-login";

@NgModule({
  ...
  providers: [
    AuthService
  ]
})
export class AppModule {
  constructor() {
    Angular2SocialLoginModule.initWithProviders(providers);
  }
}

关于angular - 不支持调用 Angular2SocialLoginModule 函数调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42688744/

相关文章:

Angular 2 组件未导航到另一个组件

css - md-menu 覆盖 Angular 2 中的默认最大宽度

javascript - 用于简单悬停的 Angular2 动画,没有任何状态变化

angular - 从 Angular 上传文件到 ASP.NET Core

javascript - 如何生成一个新的 Angular 4 项目而不是创建生成 Angular 6?

angular - Bootstrap \SASS : Wrong number of arguments (3 for 2) for `table-row-variant'

javascript - Angular 2 router.navigate

angular - Ionic 2 Angular 2 HTTP 将 Base64 图像发布到服务器导致在发送之前清理不安全的 URL

angular - 无法取消当前导航并从根组件导航到其他地方

angular - 在 NgFor 循环中访问元素