最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using window opener for a function in AngularJS - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question edited Jun 2, 2014 at 13:36 DrMikey asked Jun 2, 2014 at 13:29 DrMikeyDrMikey 4054 silver badges13 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 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();
发布评论

评论列表(0)

  1. 暂无评论