Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda