Skip to content

Commit

Permalink
fix: (platform) Fixing unsubscribe error onDestroy of DynamicPage com…
Browse files Browse the repository at this point in the history
…ponent (#3795)
  • Loading branch information
KevinOkamoto committed Nov 10, 2020
1 parent 1a22c08 commit 3b2b015
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ export class DynamicPageComponent extends BaseComponent implements AfterContentI
/**
* subscription for when collapse value has changed
*/
private _collapseValSubscription: Subscription;
private _collapseValSubscription: Subscription = new Subscription();

/**
* @hidden
* subscription for when content is scrolled
*/
private _scrollSubscription: Subscription;
private _scrollSubscription: Subscription = new Subscription();

/** @hidden */
constructor(
Expand All @@ -131,6 +131,9 @@ export class DynamicPageComponent extends BaseComponent implements AfterContentI
private _zone: NgZone
) {
super(_cd);
if (this._collapseValSubscription) {
this._collapseValSubscription.unsubscribe();
}
this._collapseValSubscription = this._dynamicPageService.$collapseValue.subscribe((val) => {
this._setTabsPosition();
this._setContainerPosition();
Expand Down Expand Up @@ -184,6 +187,9 @@ export class DynamicPageComponent extends BaseComponent implements AfterContentI
* Snap the header to expand or collapse based on scrolling. Uses CDKScrollable.
*/
snapOnScroll(): void {
if (this._scrollSubscription) {
this._scrollSubscription.unsubscribe();
}
this._scrollSubscription = this._scrollDispatcher.scrolled(10).subscribe((cdk: CdkScrollable) => {
this._zone.run(() => {
const scrollPosition = cdk?.measureScrollOffset('top');
Expand Down

0 comments on commit 3b2b015

Please sign in to comment.