mcabreradev
5/6/2017 - 3:36 AM

AngularJS image onload directive

AngularJS image onload directive

app.module['myApp'].directive('imageOnload', function() {
    return {
        restrict: 'A',
        link: function(scope, element, attrs) {
            element.bind('load', function() {
                // call the function that was passed
                scope.$apply(attrs.imageOnload);
                
                // usage: <img ng-src="src" image-onload="imgLoadedCallback()" />
            });
        }
    };
});