我有一个使用API​​的函数,该函数将我重定向到回调URL。然后,我想在我的基本javascript中执行一个函数。我可以使用window.opener来执行该函数,只要将该函数保留在单独的,无 Angular JS脚本中即可。但是,当我尝试执行 Angular 函数时,只会得到未定义的错误。

为了清楚起见,这是的工作原理:

callbackpage.html:

window.opener.inviteCallback();

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

现在不起作用:

callbackpage.html:
window.opener.$scope.inviteCallback();

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

我正在使用Requests API使用facebook connect。

最佳答案

试试这个,添加$ window作为对 Controller 的依赖。

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

然后使用以下命令调用inivteCallback,
window.opener.inviteCallback();

10-05 20:50
查看更多