@@ -3,6 +3,7 @@ import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
33import { DOCUMENT } from '@angular/common' ;
44import { HttpClient } from '@angular/common/http' ;
55import { Observable , Subject } from 'rxjs' ;
6+ import { PlatformUtil } from '../core/utils' ;
67
78/**
89 * Event emitted when a SVG icon is loaded through
@@ -48,14 +49,19 @@ export class IgxIconService {
4849 private _familyAliases = new Map < string , string > ( ) ;
4950 private _cachedSvgIcons = new Map < string , Map < string , SafeHtml > > ( ) ;
5051 private _iconLoaded = new Subject < IgxIconLoadedEvent > ( ) ;
51- private _domParser = new DOMParser ( ) ;
52+ private _domParser : DOMParser ;
5253
5354 constructor (
5455 @Optional ( ) private _sanitizer : DomSanitizer ,
5556 @Optional ( ) private _httpClient : HttpClient ,
56- @Optional ( ) @Inject ( DOCUMENT ) private _document : any
57+ @Optional ( ) private _platformUtil : PlatformUtil ,
58+ @Optional ( ) @Inject ( DOCUMENT ) private _document : any ,
5759 ) {
5860 this . iconLoaded = this . _iconLoaded . asObservable ( ) ;
61+
62+ if ( this . _platformUtil ?. isBrowser ) {
63+ this . _domParser = new DOMParser ( ) ;
64+ }
5965 }
6066
6167 /**
@@ -188,7 +194,7 @@ export class IgxIconService {
188194 private cacheSvgIcon ( name : string , value : string , family = this . _family , stripMeta : boolean ) {
189195 family = ! ! family ? family : this . _family ;
190196
191- if ( name && value ) {
197+ if ( this . _platformUtil ?. isBrowser && name && value ) {
192198 const doc = this . _domParser . parseFromString ( value , 'image/svg+xml' ) ;
193199 const svg = doc . querySelector ( 'svg' ) as SVGElement ;
194200
0 commit comments