I want to append a authentication token to the angular js ngSrc url request. So how can I pass this token with ngSrc
directive?
Asked
Active
Viewed 1,453 times
0

T J
- 42,762
- 13
- 83
- 138

Aniket Patil
- 37
- 7
-
2Use an http interceptor – JB Nizet May 23 '16 at 06:34
3 Answers
1
ngSrc is not using $http internally, so the interceptor alone will not work. It just sets the src-attribute. From my point of view you will have to write a custom directive like"ngHttpSrc", which is using the $http services.
1
Use http-src instead of ng-src and it will fetch images using the $http service - meaning Authorization headers added via interceptors will be present - then build a Blob and set the src to an objectURL.
Reference:https://github.com/dougmoscrop/angular-img-http-src

Gitaram Kanawade
- 341
- 1
- 4
- 19
0
Like JB mentioned in comments, use an interceptor
// alternatively, register the interceptor via an anonymous factory
$httpProvider.interceptors.push(function($q, dependency1, dependency2) {
return {
'request': function(config) {
// manipulate the request here
// You can filter specific requests if you want
config.headers.token ="whatever";
return config;
}
};
});

T J
- 42,762
- 13
- 83
- 138