Let's look at this simple example:

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

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

   getInnerHTML(){
   }
}

I expect getInnerHTML function to return:

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

How can i achieve that?

1 Answers

0
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;
}