From 9b05fbc990699353fc6498122fdc345767c66fe3 Mon Sep 17 00:00:00 2001 From: mrLarbi Date: Fri, 23 Sep 2016 21:58:48 +0200 Subject: [PATCH 1/3] feat($anchorScroll) Allow $anchorScroll to have a numeric input Ref #14680 Before the change :
$anchorScroll(7); Does not work After the change :
$anchorScroll(7); works --- src/ng/anchorScroll.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ng/anchorScroll.js b/src/ng/anchorScroll.js index 50512b173253..d37a877ce1cf 100644 --- a/src/ng/anchorScroll.js +++ b/src/ng/anchorScroll.js @@ -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; From 8d282307d8e36431e9de72325f89b2e895538e3d Mon Sep 17 00:00:00 2001 From: mrLarbi Date: Fri, 23 Sep 2016 22:47:35 +0200 Subject: [PATCH 2/3] feat($anchorScroll) Allow $anchorScroll to have a numeric input Ref #14680 Before the change :
$anchorScroll(7); Does not work After the change :
$anchorScroll(7); works --- src/ng/anchorScroll.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ng/anchorScroll.js b/src/ng/anchorScroll.js index d37a877ce1cf..77e8ded5ce37 100644 --- a/src/ng/anchorScroll.js +++ b/src/ng/anchorScroll.js @@ -239,8 +239,8 @@ function $AnchorScrollProvider() { function scroll(hash) { //Allow hash to be a number - if(isNumber(hash)) hash = hash.toString(); - + if (isNumber(hash)) hash = hash.toString(); + hash = isString(hash) ? hash : $location.hash(); var elm; From f86bcf1771a0b5497b60197929f06a66a3567a62 Mon Sep 17 00:00:00 2001 From: mrLarbi Date: Sun, 25 Sep 2016 18:21:00 +0200 Subject: [PATCH 3/3] feat($anchorScroll) Allow $anchorScroll to have a numeric input Ref #14680 Before the change :
$anchorScroll(7); Does not work After the change :
$anchorScroll(7); works --- test/ng/anchorScrollSpec.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/ng/anchorScrollSpec.js b/test/ng/anchorScrollSpec.js index 8f7e4a2c8829..22fb13608f11 100644 --- a/test/ng/anchorScrollSpec.js +++ b/test/ng/anchorScrollSpec.js @@ -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'))); }); });