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

165
Views
Add Component or Directive to HTML template received from the server

Let's say an endpoint returns this HTML:

<div data-type="section">
    <div data-type="section-header">
        Section 1
    </div>
    <div data-type="section-body">
        Lorem ipsum
    </div>
</div>

Above template will be stored in component property sections. In an Angular app we will append this HTML to the page via <div class="sections-container" [innerHtml]="sections"></div>.

Before appending HTML template to innerHtml, is it possible to add component or directive to the HTML template received from the backend?

For example we have HighlightDirective, which will set background to yellow and we want to apply it to data-type="section-header" element, so that HTML template will look like this:

<div data-type="section">
    <div data-type="section-header" appHighlight>
        Section 1
    </div>
    <div data-type="section-body">
        Lorem ipsum
    </div>
</div>

Will Angular automatically recognize the appHighlight directive and add it to the component tree? Or it's necessary to hydrate this HTML template?

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

0

The solution that I have found it is wrapped HTML into anonymous component and handle string from BE. Then compile that and looks like everything is ok.

Stackblitz example

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!