I have an image I need to display using Angular within the ionic mobile framework.
The HTML looks like this:
<div class="avatar-image" [ngStyle]="{'background-image': getAssetImage(item.imageUrl)}"></div>
The existing Angular typescript looks like this:
public getAssetImage(image) {
const imagepath = Constants.mediaUrl + '/' + image;
return "url('" + imagepath + "')";
}
Recently the image assets have been secured so I need to provide a valid access token to get the image.
There is an existing service which gives me the token as an Observable:
this.authService.getToken()
Ideally what I would really like to do is find a way to add that token as an authorization header but I'm not sure that is possible. I've tried using HTTP interceptors which work fine on an ordinary GET but do not get invoked for CSS 'background-image'.
At this stage what I would settle for is just being able to add the token as a query parameter to the URL so that is looks like this:
https://myserver/myimage.jpg?access_token=theTokenValueThatComesFrom_authService.getToken
I cannot figure how to make this work with the Observable getToken() method.