Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module:icon): fix old icon element not removed #7188

Merged
merged 2 commits into from Jan 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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