I am attempting to sanitize a url to use as the data attribute for an object tag to display an svg.
my.page.html
<object [id]="'chr'+index" [data]="SVGToView[0] | safe" type="image/svg+xml"></object>
my.page.ts
SVGToView:Array<any> = ['../../assets/graphic.svg'];
safe.pipe.ts
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({
name: 'safe'
})
export class SafePipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {}
transform(url: string) {
console.log(this.sanitizer.bypassSecurityTrustResourceUrl(url));
return this.sanitizer.bypassSecurityTrustResourceUrl(url);
}
}
Throws error:
SafeResourceUrlImpl {changingThisBreaksApplicationSecurity: "../../assets/graphic.svg"}
The pipe works fine, the svg is fine (correct location and hardcoded it displays ok) Would you know why the Domsanitizer is not accepting this resource url? Thanks