Skip to content

Commit

Permalink
fix(module:icon): fix old icon element not removed
Browse files Browse the repository at this point in the history
close #7186
  • Loading branch information
wendellhu committed Jan 5, 2022
1 parent 77db914 commit 052e8ee
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion components/icon/icon.directive.ts
Expand Up @@ -5,6 +5,7 @@

import {
AfterContentChecked,
ChangeDetectorRef,
Directive,
ElementRef,
Input,
Expand Down Expand Up @@ -74,7 +75,8 @@ export class NzIconDirective extends IconDirective implements OnInit, OnChanges,
private destroy$ = new Subject<void>();

constructor(
private ngZone: NgZone,
private readonly ngZone: NgZone,
private readonly changeDetectorRef: ChangeDetectorRef,
elementRef: ElementRef,
public iconService: NzIconService,
public renderer: Renderer2,
Expand Down Expand Up @@ -138,6 +140,11 @@ export class NzIconDirective extends IconDirective implements OnInit, OnChanges,
from(this._changeIcon())
.pipe(takeUntil(this.destroy$))
.subscribe(svgOrRemove => {
// The _changeIcon method would call Renderer to removed node, 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);
Expand Down

0 comments on commit 052e8ee

Please sign in to comment.