Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i what LazyLoading images with Unveil inside an Angular app. Unveil uses the real Image URL in data-src and can't use a custom "data attribute" like data-unveil.

The Problem is that Angular is automatically converting "data-src" to "src". WTF!

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app>
    <ul>
        <li>Angular uses data-src as src attribute</li>
        <li ng-repeat="foo in ['Photo A', 'Photo B']">
            <img data-src="http://placehold.it/250x150&text;={{foo}}" src="http://placehold.it/250x150&text;=LazyLoad" />{{foo}}
        </li>
    </ul>
    <ul>
        <li>Changed "data-src" to "data-unveil", but unveil can't use it</li>
        <li ng-repeat="bar in ['Photo A', 'Photo B']">
            <img data-unveil="http://placehold.it/250x150&text;={{bar}}" src="http://placehold.it/250x150&text;=LazyLoad" />{{bar}}
        </li>
    </ul>
</div>

share|improve this question
    
Angular is not automatically converting "data-src" to "src", I don't know what you are talking about: jsfiddle.net/a7doobqt (it would do that if for "data-ng-src", because that would conflict with the ngSrc directive, but that's not your case) –  Josep Sep 19 at 6:55
    
After running the snippet, the first img tag looks like this "<img data-src="placehold.it/250x150&amp;text={{foo}}" src="placehold.it/250x150&amp;text=Photo A">" –  Sinky Sep 19 at 8:01
    

1 Answer 1

You can use a directive:

app.directive('unveil', function () {
  return {
    link: function (scope, element, attrs) {
        $(element).unveil();            
    }
  };
});

http://plnkr.co/edit/9KLLqHiT4KC2Z9onUizy?p=preview

Rule of thumb: always use directives if you want to integrate jquery plugins.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.