Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
Mostrar svg dinámicamente en angular

Estoy creando un proyecto usando angular, en mi proyecto quiero mostrar svg dinámicamente en la página html angular, pero solo mostrará una cadena.

Aquí está el código:

 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>

La página se muestra justo debajo de la cadena

 <?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>

Intenté usar innerhtml, pero solo mostrará texto html, no color y otras cosas de svg

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

necesitas inyectar DomSanitizer

 import {DomSanitizer} from '@angular/platform-browser' constructor(public sanitizer:DomSanitizer){}

Entonces puedes escribir

 <div [innerHTML]="sanitizer.bypassSecurityTrustHtml(canvas)"></div>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!