Skip to content

Commit

Permalink
fix(module:icon): fix old icon element not removed (#7188)
Browse files Browse the repository at this point in the history
* fix(module:icon): fix old icon element not removed

close #7186

* fix: fix typo
  • Loading branch information
wendell committed Jan 10, 2022
1 parent 77db914 commit 67ac573
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 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,12 @@ export class NzIconDirective extends IconDirective implements OnInit, OnChanges,
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);
Expand Down

0 comments on commit 67ac573

Please sign in to comment.