2

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

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

This will still fetch the images but will just not show them. With an e-mail client, you do not want to even request the images. Use ng-if to prevent the loading of images.
@musically_ut could you provide an answer with example as I am relatively new to Angular and I am not sure how should I use ng-if in a html content (coming from non-angular source)
@DaGhostmanDimitrov Use the solution above but with ng-if instead of ng-show.
0

Here is a way where you can show picture in angular. All you need to add is a boolean which is true when it's not spam.

Html :

<!-- language: html -->
<div ng-app ng:controller="ShowHideController">
    <div ng-repeat='image in images'>
        <img ng-src="{{image}}"/>
    </div>
    <button ng-click='showImage()'> show image </button>
<div>

Javascript :

    function ShowHideController($scope) {

    $scope.showImage = function(){
        $scope.images = ['https://www.google.com/images/srpr/logo3w.png'];
    }
}

Here is the jsFiddle

Also what you can do is when it's true that its spam . Set the $scope.images to nothing.

Comments

0

To achieve what OP wants, i think the best way is to use:

<img ng-src="{{vm.isVisible ? 'path/to/image' : ''}}" />

This prevents the image from being loaded.

Comments

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.