문제

My server returns a base64-encoded image and I want to send it to the client on some event foo. The way I currently have it is as such:

index.html

...
<img src="{{data}}"></img>
...

controller.js

...
$scope.foo = function (result) {
     $scope.data = result;
}
....

When, foo happens, result is a base64 encoded image and the img element starts rendering, as expected. The problem is that when the page loads initially, a request to /{{data}} will fire to get the image and 404. How can I avoid having this rogue request fire when the page initially renders? What is the proper way of doing this, if not how I'm doing it?

도움이 되었습니까?

해결책

To prevent the browser attempting to fetch the literal url /{{data}}, use the ng-src directive instead of src in your image tag.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top