Answer the question
In order to leave comments, you need to log in
How to pass a value to a template?
I pass the path value (svg) to the child component
<svg width="100%" height="521.2854" version="1.1" viewBox="0 0 300 300">
<svg:g app-quiz-svg [svgshow]="quiz?.textCategory[numPage].textContentSvg" />
</svg>
quiz?.textCategory[numPage].textContentSvg
, then the normal path is displayed - everything is fine here. export class SvgComponent {
@Input() svgshow : string;
svg:any;
constructor(private sanitizer: DomSanitizer) {
this.svg = this.sanitizer.bypassSecurityTrustHtml(this.svgshow);
}
}
<svg:g [innerHTML]="svg" transform="translate(-8735.7488,-7966.7338)">
undefined
Answer the question
In order to leave comments, you need to log in
The constructor does not yet have the value of the Input parameters. Therefore, the best option here is to use the ngOnChanges hook.
...
ngOnChanges() {
this.svg = this.sanitizer.bypassSecurityTrustHtml(this.svgshow);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question