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

229
Views
¿Cómo obtener la identificación de un div de safeHtml?

Tengo un html guardado en la base de datos, que obtengo de la llamada API. esta es la respuesta

ex.

 htmlText = <div class="dragBlock"> <div id="Name">Test</div> <div id="Age">23</div> </div>

A la vista, estoy mostrando esto como

 <div class="preview"> <div [innerHtml] = "htmlText | safeHtml"> </div> </div>

esto funciona bien, pero quiero cambiar el Html interno de id Name y Age

En el archivo ts estoy haciendo esto

 document.getElementById('Name').innerHtml = 'UserName';

pero esto no funciona, ¿podemos hacer esto en Angular? Si es así, ¿cómo?

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

0

Puede usar una tubería para manipular el HTML.

 import { Pipe, PipeTransform } from '@angular/core'; import { DomSanitizer } from '@angular/platform-browser'; @Pipe({ name: 'modify' }) export class ModifyPipe implements PipeTransform { constructor(private _domSanitizer: DomSanitizer) {} transform(html: string, args?: any): any { return this._domSanitizer.bypassSecurityTrustHtml(this.modify(html)); } private modify(html: string): string { // Do your manipulation here by replacing with regex return string; } } <p [innerHTML]="htmlText | modify"></p>
about 4 years ago · Juan Pablo Isaza Report

0

Necesitas usarlo así:

 document.getElementById('Name').innerHTML = 'UserName';

Vea este Stackblitz: https://stackblitz.com/edit/angular-sbxeon?file=src%2Fapp%2Fapp.component.ts

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!