Skip to content

Commit

Permalink
fix(module:tooltip): fix tooltip component not destory (#4291)
Browse files Browse the repository at this point in the history
close #4103
  • Loading branch information
vthinkxie authored Oct 15, 2019
1 parent cbfc5ed commit 05cbd9f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions components/tooltip/base/nz-tooltip-base.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
AfterViewInit,
ComponentFactory,
ComponentFactoryResolver,
ComponentRef,
ElementRef,
EventEmitter,
Input,
Expand All @@ -37,6 +38,7 @@ export abstract class NzTooltipBaseDirective implements OnChanges, OnInit, OnDes
specificContent?: NzTSType | null;
specificTrigger?: NzTooltipTrigger;
specificPlacement?: string;
tooltipRef: ComponentRef<NzTooltipBaseComponent>;

/**
* @deprecated 9.0.0. This is deprecated and going to be removed in 9.0.0.
Expand Down Expand Up @@ -190,6 +192,9 @@ export abstract class NzTooltipBaseDirective implements OnChanges, OnInit, OnDes
ngOnDestroy(): void {
this.$destroy.next();
this.$destroy.complete();
if (this.tooltipRef) {
this.tooltipRef.destroy();
}
}

show(): void {
Expand All @@ -215,12 +220,12 @@ export abstract class NzTooltipBaseDirective implements OnChanges, OnInit, OnDes
protected createDynamicTooltipComponent(): void {
this.isDynamicTooltip = true;

const tooltipRef = this.hostView.createComponent(this.componentFactory);
this.tooltipRef = this.hostView.createComponent(this.componentFactory);

this.tooltip = tooltipRef.instance;
this.tooltip = this.tooltipRef.instance;
this.renderer.removeChild(
this.renderer.parentNode(this.elementRef.nativeElement),
tooltipRef.location.nativeElement
this.tooltipRef.location.nativeElement
); // Remove the component's DOM because it should be in the overlay container.

// If the tooltip component is dynamically created, we should set its origin before updating properties to
Expand Down

0 comments on commit 05cbd9f

Please sign in to comment.