最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - AngularJS binding in 'src' attribute of <img> tag - Stack Overflow

programmeradmin4浏览0评论

I have a table with many rows and each row has a preview image to be shown on the top right corner when mouse is hovering the row.

This is how I put the image tag with AngularJS binding for URL in src attribute:

<img src="{{imageUrl}}"/>

But there is the following error in console:

GET http://localhost/#/imageUrl 404 (Not Found)

How to get rid of this error in browser console?

I have a table with many rows and each row has a preview image to be shown on the top right corner when mouse is hovering the row.

This is how I put the image tag with AngularJS binding for URL in src attribute:

<img src="{{imageUrl}}"/>

But there is the following error in console:

GET http://localhost/#/imageUrl 404 (Not Found)

How to get rid of this error in browser console?

Share Improve this question edited Mar 1, 2017 at 15:57 Mistalis 18.3k13 gold badges77 silver badges97 bronze badges asked Jan 6, 2017 at 9:52 Dan D.Dan D. 8,5576 gold badges44 silver badges77 bronze badges 1
  • 1 Use ng-src instead of src – David R Commented Jan 6, 2017 at 9:53
Add a comment  | 

2 Answers 2

Reset to default 19

Angular has its own directive for img, called ng-src:

<img ng-src="{{imageUrl}}"/>

You need to use ng-src instead of src in your <img> tag.

The documentation says like this,

Using Angular markup like {{hash}} in a src attribute doesn't work right: The browser will fetch from the URL with the literal text {{hash}} until Angular replaces the expression inside {{hash}}. The ngSrc directive solves this problem.

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

Hope this helps!

发布评论

评论列表(0)

  1. 暂无评论