1- import { Component , Input , OnChanges } from '@angular/core' ;
1+ import { Component , Inject , Input , OnChanges , PLATFORM_ID } from '@angular/core' ;
22import { DomSanitizer , SafeHtml } from '@angular/platform-browser' ;
33import { Pipe , PipeTransform } from '@angular/core' ;
4- import { NgStyle } from '@angular/common' ;
4+ import { isPlatformBrowser , NgStyle , CommonModule , NgOptimizedImage } from '@angular/common' ;
55
66// SafeHtml pipe to bypass Angular's sanitization
77@Pipe ( { name : 'safeHtml' , standalone : true } )
@@ -16,7 +16,7 @@ export class SafeHtmlPipe implements PipeTransform {
1616@Component ( {
1717 selector : 'dl-icon' ,
1818 standalone : true ,
19- imports : [ NgStyle , SafeHtmlPipe ] ,
19+ imports : [ NgStyle , SafeHtmlPipe , CommonModule ] ,
2020 template : `
2121 <svg
2222 xmlns="http://www.w3.org/2000/svg"
@@ -27,7 +27,7 @@ export class SafeHtmlPipe implements PipeTransform {
2727 role="img"
2828 focusable="false"
2929 >
30- <g [innerHTML]="iconSvg | safeHtml"></g>
30+ <g *ngIf="isBrowser" [innerHTML]="iconSvg | safeHtml"></g>
3131 </svg>
3232 ` ,
3333} )
@@ -41,6 +41,16 @@ export class DlIconComponent implements OnChanges {
4141
4242 mergedStyles : any = { } ;
4343
44+ isBrowser : boolean = false ;
45+
46+ constructor (
47+ @Inject ( PLATFORM_ID ) private platformId : Object ,
48+ ) { }
49+
50+ ngOnInit ( ) : void {
51+ this . isBrowser = isPlatformBrowser ( this . platformId ) ;
52+ }
53+
4454 ngOnChanges ( ) : void {
4555 // Merge the fill color (defaulting to currentColor) with user-provided styles
4656 this . mergedStyles = {
@@ -172,6 +182,9 @@ export class DlIconComponent implements OnChanges {
172182 * The raw SVG path data (or <path> etc.) for the current icon.
173183 */
174184 get iconSvg ( ) : string {
185+ if ( ! isPlatformBrowser ( this . platformId ) ) {
186+ return '' ;
187+ }
175188 const iconDef = this . icons [ this . icon ] ;
176189 if ( ! iconDef ) {
177190 return '' ;
0 commit comments