how to add css using nativeelement in angular

Solutions on MaxInterview for how to add css using nativeelement in angular by the best coders in the world

showing results for - "how to add css using nativeelement in angular"
Gabriel
17 Jun 2020
1import { ..., AfterViewInit, ElementRef, ViewChild, Renderer2, ... } from '@angular/core';
2...
3export class AdvertisementDirective implements AfterViewInit {
4
5  @ViewChild('templateRefName') el: ElementRef;
6
7  constructor(
8    private renderer: Renderer2
9  ) {
10  }
11
12  ngAfterViewInit() {
13    this.renderer.setStyle(this.el.nativeElement, 'background', 'yellow');
14    this.renderer.setProperty(this.el.nativeElement, 'innerHTML', '<p>Hello World<p>');
15  }
16
17}
18