fix(menu,tooltip): Ensure subscription exists before unsubscribing. (#3078)

This commit is contained in:
Thomas Shafer
2017-03-09 13:58:32 -08:00
committed by tinayuangao
parent 5d6920dde6
commit 84b5c3b061
4 changed files with 22 additions and 2 deletions
+3 -1
View File
@@ -76,7 +76,9 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
}
ngOnDestroy() {
this._tabSubscription.unsubscribe();
if (this._tabSubscription) {
this._tabSubscription.unsubscribe();
}
}
/**
+6
View File
@@ -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({
+10
View File
@@ -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({
+3 -1
View File
@@ -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 */