mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(menu,tooltip): Ensure subscription exists before unsubscribing. (#3078)
This commit is contained in:
committed by
tinayuangao
parent
5d6920dde6
commit
84b5c3b061
@@ -76,7 +76,9 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this._tabSubscription.unsubscribe();
|
||||
if (this._tabSubscription) {
|
||||
this._tabSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -384,6 +384,12 @@ describe('MdMenu', () => {
|
||||
|
||||
});
|
||||
|
||||
describe('destroy', () => {
|
||||
it('does not throw an error on destroy', () => {
|
||||
const fixture = TestBed.createComponent(SimpleMenu);
|
||||
expect(fixture.destroy.bind(fixture)).not.toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@Component({
|
||||
|
||||
@@ -402,6 +402,15 @@ describe('MdTooltip', () => {
|
||||
expect(tooltipDirective._tooltipInstance).toBeNull();
|
||||
}));
|
||||
});
|
||||
|
||||
describe('destroy', () => {
|
||||
it('does not throw an error on destroy', () => {
|
||||
const fixture = TestBed.createComponent(BasicTooltipDemo);
|
||||
fixture.detectChanges();
|
||||
delete fixture.componentInstance.tooltip.scrollSubscription;
|
||||
expect(fixture.destroy.bind(fixture)).not.toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@Component({
|
||||
@@ -417,6 +426,7 @@ class BasicTooltipDemo {
|
||||
position: string = 'below';
|
||||
message: string = initialTooltipMessage;
|
||||
showButton: boolean = true;
|
||||
@ViewChild(MdTooltip) tooltip: MdTooltip;
|
||||
}
|
||||
|
||||
@Component({
|
||||
|
||||
@@ -161,7 +161,9 @@ export class MdTooltip implements OnInit, OnDestroy {
|
||||
this._disposeTooltip();
|
||||
}
|
||||
|
||||
this.scrollSubscription.unsubscribe();
|
||||
if (this.scrollSubscription) {
|
||||
this.scrollSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
/** Shows the tooltip after the delay in ms, defaults to tooltip-delay-show or 0ms if no input */
|
||||
|
||||
Reference in New Issue
Block a user