Skip to content

CSS code snippet – How to add using nativeelement in angular?

import { ..., AfterViewInit, ElementRef, ViewChild, Renderer2, ... } from '@angular/core';
export class AdvertisementDirective implements AfterViewInit {

  @ViewChild('templateRefName') el: ElementRef;

    private renderer: Renderer2
  ) {

  ngAfterViewInit() {
    this.renderer.setStyle(this.el.nativeElement, 'background', 'yellow');
    this.renderer.setProperty(this.el.nativeElement, 'innerHTML', '<p>Hello World<p>');

See also  from How many ways we can define props with TypeScript react?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.