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

Commit bfe48dc

Browse files
committed
Combine duplicated logic
1 parent 7941daa commit bfe48dc

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ export class TableOfContents implements OnInit {
5555

5656
this._route.fragment.takeUntil(this._destroyed).subscribe(fragment => {
5757
this._urlFragment = fragment;
58-
59-
const target = document.getElementById(this._urlFragment);
60-
if (target) {
61-
target.scrollIntoView();
62-
}
58+
this.scrollFragmentIntoView();
6359
});
6460
}
6561

@@ -83,7 +79,11 @@ export class TableOfContents implements OnInit {
8379

8480
updateScrollPosition(): void {
8581
this.links = this.createLinks();
82+
this.scrollFragmentIntoView();
83+
}
8684

85+
/** Find the target from the url fragment and scroll it into view. */
86+
private scrollFragmentIntoView(): void {
8787
const target = document.getElementById(this._urlFragment);
8888
if (target) {
8989
target.scrollIntoView();

0 commit comments

Comments
 (0)