RevillWeb / angular-preload-image

A simple AngularJS module to make it easy to pre-load images.
MIT License
70 stars 29 forks source link

It kills other directives #11

Closed kitce closed 7 years ago

kitce commented 7 years ago

This does not work <img class="my-image" preload-image default-image="default.jpg" fallback-image="error.jpg" ng-src="my-image.jpg"/>

This works <img class="my-image" ng-src="my-image.jpg"/>

my-image.directive.js

function myImage () {
    return {
        restrict: 'C',
        link: function (scope, $element, attrs) {
            $element.on('load error', function () { // this line is not triggered
                doSomethingWhenTheImageIsLoaded();
            });
        }
    };
}

myImage.$inject = [];
angular.module('chat').directive('myImage', myImage);
kitce commented 7 years ago

I found it's my problem, I forgot to $compile the html