DaGhostman Dimitrov DaGhostman Dimitrov - 1 month ago 6
AngularJS Question

Prevent image loading with angular

I am looking in building a simple email client and I am stuck at the point, where the client should ask if the user wants to see images/hide them on spam messages. Any approaches are welcome.


How to prevent images from loading within a 'container' with angularJS


Please, note:
I am looking for angular solution so please do not suggest jQuery as they do not play nice together. Although pure JS is welcomed

'Do The Simplest Thing That Could Possibly Work' kind of solution

Answer

You can use ng-if feature

In controller

$scope.toggleImage = false; // true - Show, false - Hide. By default hide image.

In View template

<img ng-src="" ng-if="toggleImage">
<a href="" ng-click="toggleImage = !toggleImage">Toggle Image</a>

Thanks @musically_ut for the correction.