Let's look at this simple example:

  selector: 'app-favorite-color',
  template: `<p>My favorite color is {{ favoriteColor }}</p>`

export class FavoriteColorComponent {
   favoriteColor: string = "red";


I expect getInnerHTML function to return:

<p>My favorite color is red</p>

How can i achieve that?

1 Answers

OneLunch Man On Best Solutions

You can inject the Element Ref in the constructor and access the nativeElement.

constructor(private el: ElementRef){}

getInnerHTML() {
  return this.el.nativeElement.innerHTML;