2

Google's platform.js script for handling web logins can end in a callback to initiate some function in our code:

<script src="https://apis.google.com/js/platform.js?onload=appStart" async defer>

In spite of the many Angular tutorials and examples, I have yet to find a way to have this callback execute in an Angular controller. How do I connect this callback to an Angular controller or other appropriate mechanism of Angular?

1 Answer 1

1

I was able to inject $window into my controller and direct third party code there. This is the result:

var app = angular.module('ga',[]);
app.controller('gac', function($scope, $window) {

    $window.appStart = function() {
        console.log('appStart()');
        gapi.load('auth2', initSigninV2);
    };

    // additional functions omitted. refer to demo
}

Note when third parties call functions in Angular, it may be necessary to update the scope with $scope.$digest().

Demo: http://jameswclark.github.io/Google-Web-Login/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.