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

feat($anchorScroll) Allow $anchorScroll to take a numeric input #15182

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/ng/anchorScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ function $AnchorScrollProvider() {
}

function scroll(hash) {
//Allow hash to be a number
if (isNumber(hash)) hash = hash.toString();

hash = isString(hash) ? hash : $location.hash();
var elm;

Expand Down
12 changes: 12 additions & 0 deletions test/ng/anchorScrollSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
});
});

Expand Down