Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Login Button using AngularJS

I am attempting to add the Facebook Login button to my website using the documentation at https://developers.facebook.com/docs/reference/plugins/login/

Now, this button is displayed in a view. The view is loaded only when the user explicitly requests to login to the website.

I am using the HTML5 version. In Step 1, I am asked to include the Javascript SDK - I do this immediately after the tag. This is located in the main page that contains the ng-view directive.

I place the code to render the login button inside the view. Problem is that if I navigate to the view by clicking on the login button in the main page, the view does not render the FB login button. However if I refresh the page (the one containing the login view), the button renders.

I have moved the code for the Javascript SDK into the login view too- both before the button is rendered and after but that also does not solve the problem. Only when refreshing the login view, the button is rendered.

So,
a) Either I need to know why this is happening and the solution or
b) Refresh in AngularJS; that is I need to know the AngularJS way to refresh the login view before it is rendered so that (I Hope) the login button gets rendered.

like image 630
user109187 Avatar asked Mar 16 '13 18:03

user109187


People also ask

How to create Facebook social login button in angular app?

In this step, create facebook social login button in angular app. So, visit src/app/app.component.html and update the following code into it: In this step, visit the src/app directory and open app.component.ts. Then add the following code into component.ts file:

What is the login button on Facebook?

The Login button is a simple way to trigger the Facebook Login process on your website or web app. If someone hasn't logged into your app yet, they'll see this button, and clicking it will open a Login dialog, starting the login flow. People who have already logged in won't see any button, or you can also choose to show a logout button to them.

Can I use the Facebook SDK with AngularJS?

As a workaround you can bundle your Facebook for JavaScript SDK calls (for example) into a service: Use the service for example like this: There are also several third party libraries simplifing the usage of the Facebook SDK for JavaScript listed on the AngularJS Guide page.

How do I use the Facebook SDK for JavaScript to login?

Once someone has clicked the Login button, and accepted the login dialog — completing the Login flow — your app can now use the Facebook SDK for JavaScript to make API calls on behalf of that person.


1 Answers

This is because Facebook renders the whole page once to find its buttons and stuff. You need to re-run parser after you load ngView.

Since you shall not do dom manipulation on the controller here is a directive version.

angular.module("myApp", []).directive("fbLogin", function($rootScope) {
    return function (scope, iElement, iAttrs) {
        if (FB) {
            FB.XFBML.parse(iElement[0]);
        }
    };
};
like image 174
Umur Kontacı Avatar answered Oct 07 '22 18:10

Umur Kontacı