简体   繁体   中英

AngularJS can produce a 404 error when using variable for image

<img lass="img-circle" src="{{p.CharmType | enumCharmUrl}}">

When having an image above in angular i get an error thrown if there is a brief moment when that variable is not available and it throws this error in the site console.

http://localhost:2087/%7B%7Bp.CharmType%20%7C%20enumCharmUrl%7D%7D 404 error

What is the best way to avoid this happening until this url is available.

Thanks

use ng-src INSTEAD of src

same applies to href

use ng-href INSTEAD of href

This applies whenever there is an expression in the src or the href

An expression being the bit in double curly brackets :)

Just use ng-src instead of src :

<img lass="img-circle" ng-src="{{p.CharmType | enumCharmUrl}}">

ngSrc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM