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

Allow $anchorScroll to have a numeric input #14680

Closed
samuelfernandez opened this issue May 26, 2016 · 3 comments
Closed

Allow $anchorScroll to have a numeric input #14680

samuelfernandez opened this issue May 26, 2016 · 3 comments

Comments

@samuelfernandez
Copy link

Do you want to request a feature or report a bug?
Request a feature

What is the current behavior?
Now $anchorScroll expects the parameter to be a string. If a number is passed, it won't work. This can lead to a confusing situation like:
<div id="7">
$anchorScroll(7); won't work

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (template: http://plnkr.co/edit/tpl:yBpEi4).
http://plnkr.co/edit/CtQeFVTxgEGtFkgaTAnE?p=preview

What is the expected behavior?
If a number is provided, cast it

What is the motivation / use case for changing the behavior?
Having html elements with a numeric id

Which versions of Angular, and which browser / OS are affected by this issue? Did this work in previous versions of Angular? Please also test with the latest stable and snapshot (https://code.angularjs.org/snapshot/) versions.
Latest version

Other information (e.g. stacktraces, related issues, suggestions how to fix)
In angular.js/src/ng/anchorScroll.js line 240 change it to:
hash = hash ? String(hash) : $location.hash();

@Narretz
Copy link
Contributor

Narretz commented May 26, 2016

We could change this but in the end ids can never be numbers. They are always strings because html attribute values are always strings.

@samuelfernandez
Copy link
Author

Yes, but if a numeric id is assigned with interpolation to the html id, you need to remember that when invoking anchorScroll you should cast it. If the function could be smarter for different input formats, this could be great!

@gkalpak
Copy link
Member

gkalpak commented May 26, 2016

I don't like converting anything to a string (e.g. String(hash)), as it would hide programming errors.
But converting numbers to strings wouldn't hurt, I guess.

I'm not 100% certain I would merge a PR with that change, but if anyone feels like submitting one, I'm sure we would consider it 😉

mrLarbi added a commit to mrLarbi/angular.js that referenced this issue Sep 23, 2016
Ref angular#14680

Before the change :

<div id="7">
$anchorScroll(7); Does not work

After the change :

<div id="7">
$anchorScroll(7); works
mrLarbi added a commit to mrLarbi/angular.js that referenced this issue Sep 23, 2016
Ref angular#14680

Before the change :

<div id="7">
$anchorScroll(7); Does not work

After the change :

<div id="7">
$anchorScroll(7); works
mrLarbi added a commit to mrLarbi/angular.js that referenced this issue Sep 25, 2016
Ref angular#14680

Before the change :

<div id="7">
$anchorScroll(7); Does not work

After the change :

<div id="7">
$anchorScroll(7); works
gkalpak pushed a commit that referenced this issue Sep 30, 2016
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
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
This allows `$anchorScroll(7)` to scroll to `<div id="7">` (although technically, the target ID is a
string, not a number).

Fixes angular#14680

Closes angular#15182
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
This allows `$anchorScroll(7)` to scroll to `<div id="7">` (although technically, the target ID is a
string, not a number).

Fixes angular#14680

Closes angular#15182
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
This allows `$anchorScroll(7)` to scroll to `<div id="7">` (although technically, the target ID is a
string, not a number).

Fixes angular#14680

Closes angular#15182
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
This allows `$anchorScroll(7)` to scroll to `<div id="7">` (although technically, the target ID is a
string, not a number).

Fixes angular#14680

Closes angular#15182
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
This allows `$anchorScroll(7)` to scroll to `<div id="7">` (although technically, the target ID is a
string, not a number).

Fixes angular#14680

Closes angular#15182
petebacondarwin pushed a commit that referenced this issue Nov 23, 2016
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
petebacondarwin pushed a commit that referenced this issue Nov 24, 2016
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
ellimist pushed a commit to ellimist/angular.js that referenced this issue Mar 15, 2017
This allows `$anchorScroll(7)` to scroll to `<div id="7">` (although technically, the target ID is a
string, not a number).

Fixes angular#14680

Closes angular#15182
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants