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

167
Views
Angular dynamic templates with innerHTML convert the method to string

I try to load html with innerHTML but it does not work.

page.ts

htmlStr = `<div [ngClass]="getClass('COLECTOR')">HELLO WORLD</div>`;

page.html

<div [class]="getClass('COLECTOR')"> </div>

When I inspect code in Chrome:

-If i use [innerHtml] the method doesn't work. See the method as string:

<div [ngclass]="getClass('COLECTOR')">HELLO WORLD</div>

-If I don't use the pipe i only see:

<div>HELLO WORLD</div>

But.............

If i put the div tag in the page.thml without load the html from the string with innerHTML it works

<div [ngClass]="getClass('COLECTOR')">HELLO WORLD</div>

when inspect the code i see:

<div class="manual">HELLO WORLD</div>

This last is what i want to get but loading the HTML from a string.

pipe

@Pipe({
  name: "domSanitizer",
})
export class DomSanitizerPipe implements PipeTransform {
  constructor(private sanitizer: DomSanitizer) {}

  transform(value: string, type: string): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl {
        switch (type) {
            case 'html':
                return this.sanitizer.bypassSecurityTrustHtml(value);
...
about 4 years ago · Santiago Gelvez
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!