Angular2 [innerHtml] angular2 tag doesn't work

前端 未结 4 931
忘掉有多难
忘掉有多难 2021-01-15 13:49

I want to inject html in my a-component with angular2 tags from another component.

@Component({
  selector: \'app-root\',
  template: \'

        
4条回答
  •  没有蜡笔的小新
    2021-01-15 14:45

    You can use Renderer2 Class for this.

    import { ElementRef, Renderer2 } from '@angular/core';
    
    constructor (
      private elementRef: ElementRef,
      private renderer: Renderer
    ) {}
    
    public ngAfertViewInit(): void {
      this.renderer
         .setElementProperty(
            this.elementRef.nativeElement, 
            'innerHTML',
            '

    Nice Title

    ' ); }

提交回复
热议问题