title: How to call an Angular $rootScope method from another global function?
body: <p>Basically, I am trying to call a $rootScope method from the Facebook Javascript SDK. The SDK code is placed directly in my HTML, something like this:</p>
  
  <pre><code>&lt;script&gt;
      window.fbAsyncInit = function() {
          // FB JavaScript SDK configuration and setup
          FB.init({
              appId: '&lt;My App ID&gt;', // FB App ID
              cookie: true, // enable cookies to allow the server to access the session
              xfbml: true, // parse social plugins on this page
              version: 'v2.8' // use graph api version 2.8
          });
  
          // Check whether the user already logged in
          FB.getLoginStatus(function(response) {
              if (response.status === 'connected') {
                  //display user data
                  getFbUserData();
              }
          });
      };
  
      // Load the JavaScript SDK asynchronously
      (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 = "//connect.facebook.net/en_US/sdk.js";
          fjs.parentNode.insertBefore(js, fjs);
      }(document, 'script', 'facebook-jssdk'));
  
      // Facebook login with JavaScript SDK
      function fbLogin() {
          FB.login(function(response) {
              if (response.authResponse) {
                  // Get and display the user profile data
                  getFbUserData();
              } else {
                  console.log('User cancelled login or did not fully authorize.');
              }
          }, {
              scope: 'email'
          });
      }
  
      // Fetch the user profile data from facebook
      function getFbUserData() {
          FB.api('/me', {
                  locale: 'en_US',
                  fields: 'id,first_name,last_name,name,email,link,gender,locale,picture'
              },
              function(response) {
                  **$rootScope.login(response);**
              });
      }
  
      // Logout from facebook
      function fbLogout() {
          FB.logout(function() {
              console.log('User has logged out.');
          });
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>Please note that in my getFbUserData method, I am trying to call a rootScope method called login directly from here. However, this does not work as it says that the rootScope object is undefined or whatever. What would be the correct way to do this? I am using Angular1.5.</p>
  
  <p>Thanks!</p>