This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix($anchorScroll): don't scroll to top when initializing and locatio…
- Loading branch information
Showing
2 changed files
with
21 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,7 +94,10 @@ function $AnchorScrollProvider() { | |
// (no url change, no $location.hash() change), browser native does scroll | ||
if (autoScrollingEnabled) { | ||
$rootScope.$watch(function autoScrollWatch() {return $location.hash();}, | ||
function autoScrollWatchAction() { | ||
function autoScrollWatchAction(newVal, oldVal) { | ||
// skip the initial scroll if $location.hash is empty | ||
if (newVal === oldVal && newVal === '') return; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
IgorMinar
via email
Author
Contributor
|
||
|
||
$rootScope.$evalAsync(scroll); | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IgorMinar : Can this actually ever happen ? To have a watchAction triggered even if
newVal === oldVal
and without being undefined (as happens the first time a watchAction is called for initialization) ?Should this rather be
if (newVal === oldVal) return;
(or am I missing something) ?