How to use Angular renderer2 to toggle a class or style

I needed to toggle a simple style for a <div> and it’s children, so I did it like this:

let parent: HTMLElement | null = document.getElementById('thirdElement');
  const children : any = parent.children;
  for(let i=1; i < children.length; i++)
  {     
    if (children[i].style.cssText.includes("display: flex;"))
    {
      this.renderer.setStyle(children[i], 'display', 'none');
    } else {
      this.renderer.setStyle(children[i], 'display', 'flex');
    }
  }

this is a simple workaround for Renderer not having getStyle or getClass methods. hope this helps.

درباره ی حمیدرضا

حمیدرضا هستم فارغ التحصیل رشته الکترونیک. رشته ام و کامپیوترها و موبایل و اینترنت و گیمینگ گوشه ای از علائق من هستن. زنده باد مایکروسافت!

این پست هم توصیه می شود:

حل مشکل JsonException: A possible object cycle was detected در ASP.Net Core

حل مشکل The anti-forgery token could not be decrypted

با ASP.NET MVC کار می کنید و با خطای ذکر شده مواجه می شوید. جای …

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد.