Using a window for a function in AngularJS

I have a function using an API that redirects me to a callback URL. Then I want to execute the function in basic javascript. I can use window.opener to execute the function while I save this function in a separate, not angular, JS script. However, when I try to execute the angular function, I just get an undefined error.

For clarity, here 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 that does not work :

callbackpage.html:

window.opener.$scope.inviteCallback();

controller.js

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

I am using facebook connection using request APIs.

+4
source share
1 answer

, $window .

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

inivteCallback,

window.opener.inviteCallback();
+9

Source: https://habr.com/ru/post/1542922/


All Articles