https://developers.facebook.com/apps/
declare var FB: any;
ngOninit()
=====================
(window as any).fbAsyncInit = function() {
FB.init({
appId : '1387547688082396',
cookie : true,
xfbml : true,
version : 'v3.1'
});
FB.AppEvents.logPageView();
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
appcomponent.html:
======================
<button (click)="submitLogin()">Facebook Authentication</button>
appcomponent.ts
======================
submitLogin(){
console.log("submit login to facebook");
// FB.login();
FB.login((response)=>
{
console.log('submitLogin',response);
if (response.authResponse)
{
this.toastr.successToastr('login successful', 'Success!');
}
else
{
console.log('User login failed');
}
});
}
We did same as it is... as you told..but in one system we are getting error "FB is not defined" but in other systems/projects it is working. Not getting how to solve it. Please let me know. Thanks in advance.
ReplyDeletemake sure to declare FB as a variable at the top.
DeleteThen use this.FB instead of FB.
This comment has been removed by the author.
ReplyDeleteerro in:"js.src = "https://connect.facebook.net/en_US/sdk.js";
ReplyDeletefjs.parentNode.insertBefore(js, fjs);" can you help me
do a cast. On js = d.createElement(s) as HTMLScriptElement;
Deletefjs.parentNode :Object is possibly 'null'
ReplyDelete