Skip to content

Commit 67ac573

Browse files
author
wendell
authored
fix(module:icon): fix old icon element not removed (#7188)
* fix(module:icon): fix old icon element not removed close #7186 * fix: fix typo
1 parent 77db914 commit 67ac573

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

components/icon/icon.directive.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import {
77
AfterContentChecked,
8+
ChangeDetectorRef,
89
Directive,
910
ElementRef,
1011
Input,
@@ -74,7 +75,8 @@ export class NzIconDirective extends IconDirective implements OnInit, OnChanges,
7475
private destroy$ = new Subject<void>();
7576

7677
constructor(
77-
private ngZone: NgZone,
78+
private readonly ngZone: NgZone,
79+
private readonly changeDetectorRef: ChangeDetectorRef,
7880
elementRef: ElementRef,
7981
public iconService: NzIconService,
8082
public renderer: Renderer2,
@@ -138,6 +140,12 @@ export class NzIconDirective extends IconDirective implements OnInit, OnChanges,
138140
from(this._changeIcon())
139141
.pipe(takeUntil(this.destroy$))
140142
.subscribe(svgOrRemove => {
143+
// The _changeIcon method would call Renderer to remove the element of the old icon,
144+
// which would call `markElementAsRemoved` eventually,
145+
// so we should call `detectChanges` to tell Angular remove the DOM node.
146+
// #7186
147+
this.changeDetectorRef.detectChanges();
148+
141149
if (svgOrRemove) {
142150
this.setSVGData(svgOrRemove);
143151
this.handleSpin(svgOrRemove);

0 commit comments

Comments
 (0)