11import { NgClass } from '@angular/common' ;
2- import {
3- afterNextRender ,
4- Component ,
5- computed ,
6- effect ,
7- ElementRef ,
8- inject ,
9- input ,
10- Renderer2 ,
11- signal ,
12- viewChild
13- } from '@angular/core' ;
2+ import { Component , computed , effect , ElementRef , inject , input , Renderer2 , viewChild } from '@angular/core' ;
143import { DomSanitizer } from '@angular/platform-browser' ;
154
165import { HtmlAttributesDirective } from '../shared/html-attr.directive' ;
@@ -19,25 +8,18 @@ import { IconSize, IIcon, NgCssClass } from './icon.interface';
198import { transformName } from './icon.utils' ;
209
2110@Component ( {
22- exportAs : 'cIconComponent' ,
23- imports : [ NgClass , HtmlAttributesDirective ] ,
24- selector : 'c-icon' ,
25- styleUrls : [ './icon.component.scss' ] ,
26- templateUrl : './icon.component.svg' ,
27- host : { ngSkipHydration : 'true' , style : 'display: none' }
11+ exportAs : 'cIconComponent' ,
12+ imports : [ NgClass , HtmlAttributesDirective ] ,
13+ selector : 'c-icon' ,
14+ styleUrls : [ './icon.component.scss' ] ,
15+ templateUrl : './icon.component.svg' ,
16+ host : { ngSkipHydration : 'true' , style : 'display: none' }
2817} )
2918export class IconComponent implements IIcon {
3019 readonly #renderer = inject ( Renderer2 ) ;
3120 readonly #elementRef = inject ( ElementRef ) ;
3221 readonly #sanitizer = inject ( DomSanitizer ) ;
3322 readonly #iconSet = inject ( IconSetService ) ;
34- readonly #hostElement = signal < ElementRef < any > | undefined > ( undefined ) ;
35-
36- constructor ( ) {
37- afterNextRender ( ( ) => {
38- this . #hostElement. set ( this . #elementRef) ;
39- } ) ;
40- }
4123
4224 readonly content = input < string | string [ ] | any [ ] > ( ) ;
4325
@@ -53,12 +35,12 @@ export class IconComponent implements IIcon {
5335
5436 readonly svgElementRef = viewChild < ElementRef > ( 'svgElement' ) ;
5537
56- readonly svgElementEffect = effect ( ( ) => {
38+ readonly # svgElementEffect = effect ( ( ) => {
5739 const svgElementRef = this . svgElementRef ( ) ;
58- const hostElement = this . #hostElement ( ) ? .nativeElement ;
40+ const hostElement : Element = this . #elementRef . nativeElement ;
5941 if ( svgElementRef && hostElement ) {
6042 const svgElement = svgElementRef . nativeElement ;
61- hostElement . classList ?. values ( ) ?. forEach ( ( item : string ) => {
43+ hostElement . classList ?. forEach ( ( item : string ) => {
6244 this . #renderer. addClass ( svgElement , item ) ;
6345 } ) ;
6446 const parentElement = this . #renderer. parentNode ( hostElement ) ;
0 commit comments