diff --git a/components/icon/icon.directive.ts b/components/icon/icon.directive.ts index f3c07d0cfe..f75e7eccf3 100644 --- a/components/icon/icon.directive.ts +++ b/components/icon/icon.directive.ts @@ -22,6 +22,7 @@ import { takeUntil } from 'rxjs/operators'; import { IconDirective, ThemeType } from '@ant-design/icons-angular'; +import { warn } from 'ng-zorro-antd/core/logger'; import { BooleanInput } from 'ng-zorro-antd/core/types'; import { InputBoolean } from 'ng-zorro-antd/core/util'; @@ -78,8 +79,8 @@ export class NzIconDirective extends IconDirective implements OnInit, OnChanges, private readonly ngZone: NgZone, private readonly changeDetectorRef: ChangeDetectorRef, elementRef: ElementRef, - public iconService: NzIconService, - public renderer: Renderer2, + public readonly iconService: NzIconService, + public readonly renderer: Renderer2, @Optional() iconPatch: NzIconPatchService ) { super(iconService, elementRef, renderer); @@ -139,18 +140,21 @@ export class NzIconDirective extends IconDirective implements OnInit, OnChanges, this.ngZone.runOutsideAngular(() => { from(this._changeIcon()) .pipe(takeUntil(this.destroy$)) - .subscribe(svgOrRemove => { - // The _changeIcon method would call Renderer to remove the element of the old icon, - // which would call `markElementAsRemoved` eventually, - // so we should call `detectChanges` to tell Angular remove the DOM node. - // #7186 - this.changeDetectorRef.detectChanges(); - - if (svgOrRemove) { - this.setSVGData(svgOrRemove); - this.handleSpin(svgOrRemove); - this.handleRotate(svgOrRemove); - } + .subscribe({ + next: svgOrRemove => { + // The _changeIcon method would call Renderer to remove the element of the old icon, + // which would call `markElementAsRemoved` eventually, + // so we should call `detectChanges` to tell Angular remove the DOM node. + // #7186 + this.changeDetectorRef.detectChanges(); + + if (svgOrRemove) { + this.setSVGData(svgOrRemove); + this.handleSpin(svgOrRemove); + this.handleRotate(svgOrRemove); + } + }, + error: warn }); }); } diff --git a/components/icon/icon.service.ts b/components/icon/icon.service.ts index 1b80b87caf..83b41e0c11 100644 --- a/components/icon/icon.service.ts +++ b/components/icon/icon.service.ts @@ -3,6 +3,7 @@ * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE */ +import { Platform } from '@angular/cdk/platform'; import { DOCUMENT } from '@angular/common'; import { HttpBackend } from '@angular/common/http'; import { Inject, Injectable, InjectionToken, OnDestroy, Optional, RendererFactory2, Self } from '@angular/core'; @@ -34,6 +35,10 @@ export const DEFAULT_TWOTONE_COLOR = '#1890ff'; export class NzIconService extends IconService implements OnDestroy { configUpdated$ = new Subject(); + protected override get _disableDynamicLoading(): boolean { + return !this.platform.isBrowser; + } + private iconfontCache = new Set(); private subscription: Subscription | null = null; @@ -76,14 +81,14 @@ export class NzIconService extends IconService implements OnDestroy { rendererFactory: RendererFactory2, sanitizer: DomSanitizer, protected nzConfigService: NzConfigService, + private platform: Platform, @Optional() handler: HttpBackend, @Optional() @Inject(DOCUMENT) _document: NzSafeAny, @Optional() @Inject(NZ_ICONS) icons?: IconDefinition[] ) { - super(rendererFactory, handler, _document, sanitizer); + super(rendererFactory, handler, _document, sanitizer, [...NZ_ICONS_USED_BY_ZORRO, ...(icons || [])]); this.onConfigChange(); - this.addIcon(...NZ_ICONS_USED_BY_ZORRO, ...(icons || [])); this.configDefaultTwotoneColor(); this.configDefaultTheme(); } diff --git a/package.json b/package.json index 0a3534c033..87f485c283 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ }, "dependencies": { "@angular/cdk": "^13.0.1", - "@ant-design/icons-angular": "^13.0.1", + "@ant-design/icons-angular": "^13.1.0", "date-fns": "^2.16.1", "ngx-hover-preload": "0.0.3" },