Angular, onLoad function on an iFrame

前端 未结 4 946
故里飘歌
故里飘歌 2020-11-28 06:16

I have this iframe working with basic JavaScript:


<         


        
4条回答
  •  春和景丽
    2020-11-28 07:04

    Commenting on a year old question. For cases where there are more than 1 iframes, I needed to bind "onload" events on to. I did this approach.

    Directive

    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

提交回复
热议问题