angular http: how to call images with custom headers?

前端 未结 5 2242
不思量自难忘°
不思量自难忘° 2020-12-09 03:28

In the html view, images are displayed like this:

 

element.image.url points to a

5条回答
  •  情深已故
    2020-12-09 04:09

    As said here you can use angular-img-http-src (bower install --save angular-img-http-src if you use Bower).

    If you look at the code, it uses URL.createObjectURL and URL.revokeObjectURL which are still draft on 19 April 2016. So look if your browser supports it.

    In order to use it, declare 'angular.img' as a dependency to your app module (angular.module('myapp', [..., 'angular.img'])), and then in your HTML you can use http-src attribute for tag.

    In your example it would be:

    Of course, this implies that you have declared an interceptor using $httpProvider.interceptors.push to add your custom header or that you've set statically your header for every requests using $http.defaults.headers.common.MyHeader = 'some value';

提交回复
热议问题