diff --git a/src/lib/menu/menu-directive.ts b/src/lib/menu/menu-directive.ts index 7bde6f80ff2a..914e15578f37 100644 --- a/src/lib/menu/menu-directive.ts +++ b/src/lib/menu/menu-directive.ts @@ -76,7 +76,9 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy { } ngOnDestroy() { - this._tabSubscription.unsubscribe(); + if (this._tabSubscription) { + this._tabSubscription.unsubscribe(); + } } /** diff --git a/src/lib/menu/menu.spec.ts b/src/lib/menu/menu.spec.ts index 1ccdbc698d3a..a5fc6ee4f98c 100644 --- a/src/lib/menu/menu.spec.ts +++ b/src/lib/menu/menu.spec.ts @@ -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({ diff --git a/src/lib/tooltip/tooltip.spec.ts b/src/lib/tooltip/tooltip.spec.ts index f13af21eca89..9700e755fc21 100644 --- a/src/lib/tooltip/tooltip.spec.ts +++ b/src/lib/tooltip/tooltip.spec.ts @@ -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({ diff --git a/src/lib/tooltip/tooltip.ts b/src/lib/tooltip/tooltip.ts index fa463026bb7a..ded39bf7ae44 100644 --- a/src/lib/tooltip/tooltip.ts +++ b/src/lib/tooltip/tooltip.ts @@ -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 */