feat($anchorScroll): convert numeric hash targets to string

This allows `$anchorScroll(7)` to scroll to `<div id="7">` (although technically, the target ID is a
string, not a number).

Fixes #14680

Closes #15182
This commit is contained in:
mrLarbi
2016-09-23 21:58:48 +02:00
committed by Georgios Kalpakas
parent 3253b55861
commit 9062bae05c
2 changed files with 14 additions and 1 deletions
+2 -1
View File
@@ -238,7 +238,8 @@ function $AnchorScrollProvider() {
}
function scroll(hash) {
hash = isString(hash) ? hash : $location.hash();
// Allow numeric hashes
hash = isString(hash) ? hash : isNumber(hash) ? hash.toString() : $location.hash();
var elm;
// empty hash, scroll to the top of the page
+12
View File
@@ -260,6 +260,18 @@ describe('$anchorScroll', function() {
addElements('id=top'),
callAnchorScroll('top'),
expectScrollingTo('id=top')));
it('should scroll to element with id "7" if present, with a given hash of type number', inject(
addElements('id=7'),
callAnchorScroll(7),
expectScrollingTo('id=7')));
it('should scroll to element with id "7" if present, with a given hash of type string', inject(
addElements('id=7'),
callAnchorScroll('7'),
expectScrollingTo('id=7')));
});
});