1
1
import { 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' ;
14
3
import { DomSanitizer } from '@angular/platform-browser' ;
15
4
16
5
import { HtmlAttributesDirective } from '../shared/html-attr.directive' ;
@@ -19,25 +8,18 @@ import { IconSize, IIcon, NgCssClass } from './icon.interface';
19
8
import { transformName } from './icon.utils' ;
20
9
21
10
@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' }
28
17
} )
29
18
export class IconComponent implements IIcon {
30
19
readonly #renderer = inject ( Renderer2 ) ;
31
20
readonly #elementRef = inject ( ElementRef ) ;
32
21
readonly #sanitizer = inject ( DomSanitizer ) ;
33
22
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
- }
41
23
42
24
readonly content = input < string | string [ ] | any [ ] > ( ) ;
43
25
@@ -53,12 +35,12 @@ export class IconComponent implements IIcon {
53
35
54
36
readonly svgElementRef = viewChild < ElementRef > ( 'svgElement' ) ;
55
37
56
- readonly svgElementEffect = effect ( ( ) => {
38
+ readonly # svgElementEffect = effect ( ( ) => {
57
39
const svgElementRef = this . svgElementRef ( ) ;
58
- const hostElement = this . #hostElement ( ) ? .nativeElement ;
40
+ const hostElement : Element = this . #elementRef . nativeElement ;
59
41
if ( svgElementRef && hostElement ) {
60
42
const svgElement = svgElementRef . nativeElement ;
61
- hostElement . classList ?. values ( ) ?. forEach ( ( item : string ) => {
43
+ hostElement . classList ?. forEach ( ( item : string ) => {
62
44
this . #renderer. addClass ( svgElement , item ) ;
63
45
} ) ;
64
46
const parentElement = this . #renderer. parentNode ( hostElement ) ;
0 commit comments