Hariharan Seenu
Hariharan Seenu

Reputation: 65

Angular 2 with Facebook API

I tried using Facebook API for logging users in to my Angular-2 application . I am getting an error in my typescript file . 'Cannot find name FB'.

    (<any>window).fbAsyncInit = function() {
            FB.init({
            appId      : '123456789012345',
            cookie     : true,
            xfbml      : true,
            version    : 'v2.8'
            });

            FB.getLoginStatus(function(response) {
                statusChangeCallback(response);
            });   
        };

Can anybody provide a solution to this? Thanks in advance!!

Upvotes: 1

Views: 1514

Answers (1)

Prasad Kudalkar
Prasad Kudalkar

Reputation: 221

You need to declare a constant to use facebook SDK with angular.

Declare FB constant right above component declaration.

declare var FB: any;
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: []
})

Then initialise facebook SDK inside your constructor function.

Upvotes: 3

Related Questions