Calling Angular2SocialLoginModule function calls n

2020-04-11 13:28发布

I am new to angular js2. Currently I am working with a web application, which uses angular2 for front-end. In this application I have used angular2-social-login for authentication purpose. But when I run the npm start I got the below error

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

When I google it, some one says that it is beacause of using angular cli in the project. But I uninstalled angular cli, still problem persists. Did any one know how to solve this issue?

My app.module.ts code is below

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 { }

I have called this module in header.component.ts, please see the header.component.ts file

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.
}
)}
}

The above is my code, Please have a look. If any more details needed please comment

3条回答
▲ chillily
2楼-- · 2020-04-11 13:48

It worked for me.

export class AppModule {
    constructor() {
        Angular2SocialLoginModule.initWithProviders(providers);
    }
}
查看更多
Anthone
3楼-- · 2020-04-11 13:51

Update

In angular2-social-login v.3.0.0 you can write:

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

Angular2SocialLoginModule.loadProvidersScripts(providers);

Old version

Remove

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

And try this:

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

@NgModule({
  ...
  providers: [
    AuthService
  ]
})
export class AppModule {
  constructor() {
    Angular2SocialLoginModule.initWithProviders(providers);
  }
}
查看更多
疯言疯语
4楼-- · 2020-04-11 14:00

Another solution to fix the above problem:

export class AppModule {
 constructor() {
}}
Angular2SocialLoginModule.initWithProviders(providers);
查看更多
登录 后发表回答