4

I've got a function using an API that redirects me to a callback URL. I then want to execute a function in my base javascript. I'm able to use window.opener to execute the function as long as I keep the function in a separate, non-angular, JS script. However, when I try to execute an angular function I just get an undefined error.

For clarity, here's what works:

callbackpage.html:

window.opener.inviteCallback();

index.html

<script>
        function inviteCallback() {
            console.log('Hey Im working')
        };
    </script>
... then onto some angular code

And now what doesn't work:

callbackpage.html:

window.opener.$scope.inviteCallback();

controller.js

.controller('MainCTRL', function($scope) {
    var inviteCallback = function() {
            console.log('Hey Im working')
        };}

I'm using facebook connect using the Requests API.

1 Answer 1

9

Try this, add $window as dependency to controller.

    myApp.controller('MyCtrl', function($scope, $window){
        $window.inviteCallback = function() {
            alert('hi');
        }           
    });

And call inivteCallback using,

window.opener.inviteCallback();
Sign up to request clarification or add additional context in comments.

2 Comments

If you are using angular in the child page, I recommend using $window.opener instead.
What happens when the Angular app is destroyed? Is there a memory leak danger?

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.