Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

195
Vistas
Show Dynamically svg on angular

I am creating project using angular, in my project i want to display dynamically svg on angular html page, but it will show only string.

Here is code:

const json = JSON.stringify(this.canvas);
 this.allCanvas.push(this.canvas.toSVG())

<div *ngFor="let canvas of allCanvas; let i = index" class="preview">
 {{canvas}}
 <!-- <img src="{{canvas}}"> -->
  
  </div>

Page is showing just below string

<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="1200" height="500" viewBox="0 0 1200 500" xml:space="preserve"> <desc>Created with Fabric.js 5.2.1</desc> <defs> </defs> <g transform="matrix(0.5 0 0 0.5 58.04 21.55)" style="" > <text xml:space="preserve" font-family="arial" font-size="40" font-style="normal" font-weight="normal" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1; white-space: pre;" ><tspan x="-95.58" y="12.57" >This is text</tspan></text> </g> </svg>

I tried using innerhtml, but it will just show html text not color and other things of svg

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

you need inject DomSanitizer

import {DomSanitizer} from '@angular/platform-browser'

constructor(public sanitizer:DomSanitizer){}

Then you can write

<div [innerHTML]="sanitizer.bypassSecurityTrustHtml(canvas)"></div>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda