Understanding a localhost Image loading error in Angular JS

后端 未结 2 1014
独厮守ぢ
独厮守ぢ 2021-01-01 16:40

How can I find the error of the following error report?

GET http://localhost:8080/img/%7B%7BCurrentPage.img%7D%7D 404 (Not Found) angular.js:2763

r.html ang         


        
2条回答
  •  [愿得一人]
    2021-01-01 17:10

    This error happens when you use img with src attribute instead of ngSrc. You should use this notation:

    
    

    The problem is that when you use src="{{CurrentPage.img}}" syntax, browser starts downloading a resource making an HTTP request before Angular resolves binding and replace {{CurrentPage.img}} with actual image path:

    http://localhost:8080/img/%7B%7BCurrentPage.img%7D%7D
    

    (urlencoded {{CurrentPage.img}}). Obviously it will result in a 404 error.

    On the other hand, ng-src attribute doesn't mean anything to browser so it won't do anything, until Angular is ready and ngSrc directive creates src attribute with proper URL.

提交回复
热议问题