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:tooltip): fix tooltip component not destory #4291

Merged
merged 1 commit into from
Oct 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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