1

I am using the facebook authentication API v2.8 in an angularJs application mostly following the document https://blog.brunoscopelliti.com/facebook-authentication-in-your-angularjs-web-app/. I have put the authentication related code in a service. Now, i want to use the facebook login button inside a component like -

<fb:login-button scope="public_profile,email" onlogin="$ctrl.checkLoginState()">
</fb:login-button>

I intend to call the authentication service from the method $ctrl.checkLoginState defined inside my component controller, but I am getting an uncaught reference error -

sdk.js:89 Uncaught ReferenceError: $ctrl is not defined(…).

Any ideas to work around this?

Cache Staheli
  • 3,510
  • 7
  • 32
  • 51
Abhishek Pandey
  • 300
  • 1
  • 13

1 Answers1

3

Was able to find a solution to this following Misko's suggestion on Call Angular JS from legacy code.

Created a javascript method to be invoked after the onlogin event is fired, and then invoked the angular component controller function explicitly like this -

angular.element($("#elementId")).scope().$ctrl.checkLoginState();

From there I can call my service.

Community
  • 1
  • 1
Abhishek Pandey
  • 300
  • 1
  • 13