Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using window opener for a function in AngularJS

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.

like image 603
DrMikey Avatar asked Jan 10 '23 12:01

DrMikey


1 Answers

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();
like image 111
msapkal Avatar answered Jan 19 '23 03:01

msapkal