DrM*_*key 4 javascript callback angularjs
我有一个使用API的函数,可以将我重定向到回调URL.然后我想在我的基础javascript中执行一个函数.只要我将函数保存在一个单独的,非角度的JS脚本中,我就可以使用window.opener来执行该函数.但是,当我尝试执行角度函数时,我只得到一个未定义的错误.
为清楚起见,这是有效的:
callbackpage.html:
window.opener.inviteCallback();
Run Code Online (Sandbox Code Playgroud)
的index.html
<script>
function inviteCallback() {
console.log('Hey Im working')
};
</script>
... then onto some angular code
Run Code Online (Sandbox Code Playgroud)
现在什么不起作用:
callbackpage.html:
window.opener.$scope.inviteCallback();
Run Code Online (Sandbox Code Playgroud)
controller.js
.controller('MainCTRL', function($scope) {
var inviteCallback = function() {
console.log('Hey Im working')
};}
Run Code Online (Sandbox Code Playgroud)
我正在使用Requests API进行facebook连接.
试试这个,添加$ window作为控制器的依赖.
myApp.controller('MyCtrl', function($scope, $window){
$window.inviteCallback = function() {
alert('hi');
}
});
Run Code Online (Sandbox Code Playgroud)
并使用,调用inivteCallback,
window.opener.inviteCallback();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5531 次 |
| 最近记录: |