Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit 1f537eb

Browse files
authored
fix(): fix sidenav scroll subscription (#284)
1 parent 9f2eb03 commit 1f537eb

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/app/shared/table-of-contents/table-of-contents.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,17 @@ export class TableOfContents implements OnInit {
6767
}
6868

6969
ngOnInit(): void {
70-
this._scrollContainer = this.container ?
71-
this._document.querySelectorAll(this.container)[0] : window;
72-
73-
this._scrollSubscription = Observable
74-
.fromEvent(this._scrollContainer, 'scroll')
75-
.debounceTime(10)
76-
.subscribe(() => this.onScroll());
70+
// On init, the sidenav content element doesn't yet exist, so it's not possible
71+
// to subscribe to its scroll event until next tick (when it does exist).
72+
Promise.resolve().then(() => {
73+
this._scrollContainer = this.container ?
74+
this._document.querySelectorAll(this.container)[0] : window;
75+
76+
this._scrollSubscription = Observable
77+
.fromEvent(this._scrollContainer, 'scroll')
78+
.debounceTime(10)
79+
.subscribe(() => this.onScroll());
80+
});
7781
}
7882

7983
ngOnDestroy(): void {

0 commit comments

Comments
 (0)