Reputation: 245
I need to load an svg file from the assets folder and stringify the content. Can't find any solution int the web but here is my approach.
let svg = await this.httpClient.get(`assets/images/result/${this.icon}.svg`)
.pipe(
map(res => {
const serializer = new XMLSerializer();
const svgString = serializer.serializeToString(<any>res);
})
).toPromise();
Upvotes: 3
Views: 4584
Reputation: 245
i figured it out.
const headers = new HttpHeaders();
headers.set('Accept', 'image/svg+xml');
const svgString =
await this.httpClient.get(`assets/images/result/${this.icon}.svg`, {headers, responseType: 'text'}).toPromise();
important is that you define the header with accept "image/svg+xml" and as responseType "text
Upvotes: 10