abhaygarg12493
abhaygarg12493

Reputation: 1605

Image loaded either if condition fails in ng-if in AngularJS

In Angular Image is loaded if condition in ng-if fails...

<div ng-if="user.image">
  <img src="assets/abc.jpg">
</div>

So Image is loaded if user.image is false.

We want that image to load only if user.image is true.

Edit Actually image does not show on UI but in chrome developer tools in Network it is loaded.

Upvotes: 2

Views: 7612

Answers (1)

Victor
Victor

Reputation: 9269

ng-if is in 1.2. Use ng-src in the IMG tag instead of src to prevent the browser from loading the image first thing before Angular gets a chance to compile the HTML.

<div ng-if="user.image">
  <img ng-src="assets/abc.jpg">
</div>

https://code.angularjs.org/1.2.28/docs/api/ng/directive/ngSrc

Upvotes: 13

Related Questions