Skip to content

Commit 77371a6

Browse files
committed
fix(menu,tooltip): Ensure subscription exists before unsubscribing.
1 parent ec7e2e4 commit 77371a6

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

src/lib/menu/menu-directive.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
6969
}
7070

7171
ngOnDestroy() {
72-
this._tabSubscription.unsubscribe();
72+
if (this._tabSubscription) {
73+
this._tabSubscription.unsubscribe();
74+
}
7375
}
7476

7577
/**

src/lib/menu/menu.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,12 @@ describe('MdMenu', () => {
384384

385385
});
386386

387+
describe('destroy', () => {
388+
it('does not throw an error on destroy', () => {
389+
const fixture = TestBed.createComponent(SimpleMenu);
390+
expect(fixture.destroy.bind(fixture)).not.toThrow();
391+
});
392+
});
387393
});
388394

389395
@Component({

src/lib/tooltip/tooltip.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,15 @@ describe('MdTooltip', () => {
398398
expect(tooltipDirective._tooltipInstance).toBeNull();
399399
}));
400400
});
401+
402+
describe('destroy', () => {
403+
it('does not throw an error on destroy', () => {
404+
const fixture = TestBed.createComponent(BasicTooltipDemo);
405+
fixture.detectChanges();
406+
delete fixture.componentInstance.tooltip.scrollSubscription;
407+
expect(fixture.destroy.bind(fixture)).not.toThrow();
408+
});
409+
});
401410
});
402411

403412
@Component({
@@ -413,6 +422,7 @@ class BasicTooltipDemo {
413422
position: string = 'below';
414423
message: string = initialTooltipMessage;
415424
showButton: boolean = true;
425+
@ViewChild(MdTooltip) tooltip: MdTooltip;
416426
}
417427

418428
@Component({

src/lib/tooltip/tooltip.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ export class MdTooltip implements OnInit, OnDestroy {
154154
this._disposeTooltip();
155155
}
156156

157-
this.scrollSubscription.unsubscribe();
157+
if (this.scrollSubscription) {
158+
this.scrollSubscription.unsubscribe();
159+
}
158160
}
159161

160162
/** Shows the tooltip after the delay in ms, defaults to tooltip-delay-show or 0ms if no input */

0 commit comments

Comments
 (0)