0

If image has 'loaded' class, i need to change image src to "{{item.preview2}}"

<div ng-repeat="item in items">
<img src="{{item.preview}}" class="grid-img" />
</div>
1
  • Ok, so what is stopping you in doing that? Commented Feb 10, 2016 at 16:19

2 Answers 2

1
directive('loaded', function(){
    return {
        restrict: 'C',
        link: function(scope){
             scope.item.preview = scope.item.preview2
        }

    }

})

and in html

<img ng-src="{{item.preview}}" class="grid-img" />
Sign up to request clarification or add additional context in comments.

2 Comments

i want to handle when image will get class="loaded"
than you need to add watcher, but it's not really angular way. You should not watch for class you should react on data changed. I think something is wrong with your task
1

In the case you describe I would just use ng-if to control what elements are rendered to the DOM. for example:

<img ng-if="item.loaded" src={{item.preview2}} class="grid-img-loaded"/>
<img ng-if="!item.loaded" src={{item.preview}} class="grid-img"/>

Hope this helps.

2 Comments

I need handle case, when image in ng-repeat will have class="loaded"
I am suggesting you use a property that is set when the item is loaded (item.loaded). From there you can control what goes in the DOM using standard angular directives.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.