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();
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With