iframe - iFrame 上的 Angular、onLoad 函数

标签 iframe angularjs

我有这个 iframe 使用基本的 JavaScript:

<iframe id="upload_iframe" name="upload_iframe" onLoad="uploadDone();"></iframe>

当 iframe 的内容加载完毕后,会触发 uploadDone(); 方法。

我如何在 Angular 中做同样的事情?我想在 iframe 加载时调用 Controller 上的函数,但到目前为止我还没有看到 ng-onload

最佳答案

评论一年前的问题。 对于超过 1 个 iframe 的情况,我需要绑定(bind)“onload”事件。 我采用了这种方法。

指令

APP.directive('iframeOnload', [function(){
return {
    scope: {
        callBack: '&iframeOnload'
    },
    link: function(scope, element, attrs){
        element.on('load', function(){
            return scope.callBack();
        })
    }
}}])

Controller

APP.controller('MyController', ['$scope', function($scope){

    $scope.iframeLoadedCallBack = function(){
        // do stuff
    }
}]);

DOM

<div ng-controller="MyController">
    <iframe iframe-onload="iframeLoadedCallBack()" src="..."></iframe>
</div>

关于iframe - iFrame 上的 Angular、onLoad 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15882326/

相关文章:

javascript - 导入外部脚本时出现 404

javascript - angular-qrcode Angular如何使用?

css - 修复屏幕中央 iframe 内的元素

iframe 内的 JavaScript mousemove 事件

javascript - AngularJS $http函数在返回时总是返回未定义

javascript - 我想用所选项目的数据填充我的编辑表单

javascript - 停止父级 iframe 内的所有音频

html - FANCYBOX:指定关闭按钮的外观

javascript - 使用 YouTube API 嵌入视频会导致 404 错误

javascript - 如何通过函数执行指令并检索它创建的样式