Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParamMap returns a number if number used in navigate #23165

Closed
narthur157 opened this issue Apr 4, 2018 · 5 comments
Closed

ParamMap returns a number if number used in navigate #23165

narthur157 opened this issue Apr 4, 2018 · 5 comments
Labels
area: router effort1: hours freq2: medium help wanted An issue that is suitable for a community contributor (based on its complexity/scope). P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent state: confirmed state: has PR type: bug/fix
Milestone

Comments

@narthur157
Copy link

narthur157 commented Apr 4, 2018

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x ] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Optional route params that are given as numbers in navigate remain as numbers until page is refreshed.

Expected behavior

Would expect this to always be a string, as paramMap.get() claims

Minimal reproduction of the problem with instructions

https://angular-gitter-gd3f8s.stackblitz.io/notTheRoot;numVal=9;strVal=14
https://stackblitz.com/edit/angular-gitter-gd3f8s

The values change every 3 seconds. On page load, numVal will be a string, but then after updating will be a number. strVal is the same, except toString is called.

What is the motivation / use case for changing the behavior?

Actual types matching types declared by api

Environment

See StackBlitz


Angular version: X.Y.Z


Browser:
- [x ] Chrome (desktop) version 65
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

@ngbot ngbot bot modified the milestone: needsTriage Apr 4, 2018
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Apr 10, 2018
@jasonaden jasonaden added the help wanted An issue that is suitable for a community contributor (based on its complexity/scope). label Apr 10, 2018
@kambleaa007
Copy link

kambleaa007 commented Apr 16, 2018

At the start they both are of type Object (Output shows)
As you declared them as Any (Line no. 13,14)
There is nothing like String as per your question
Its fine I checked with output not test cases :-

ngOnInit() {
setInterval(() => {
this.router.navigate([{
numVal: Math.floor(Math.random()*20).toString(),
strVal: Math.floor(Math.random()*20).toString()}
], {relativeTo: this.route});
}, 3000);

this.route.paramMap.subscribe((paramMap: ParamMap) => {
  this.numVal = paramMap.get('numVal');
  this.strVal = paramMap.get('strVal');

  this.numValType = typeof this.numVal;
  this.strValType = typeof this.strVal;
});

}

output:-
numVal: 11 string strVal: 16 string
numVal: 16 string strVal: 11 string

Conclusion :-
There is something goes wrong with actual implementation of paramMap.get() method and its return type is " : String" ???
How this can be fixed (Where will i get implementation code for .get() method)

Solution :-
// this is need to be put at implementation side
if(typeof (paramMap.get()) != 'String') return paramMap.get().toString();

@narthur157
Copy link
Author

narthur157 commented Apr 17, 2018 via email

AlexMokin added a commit to AlexMokin/angular that referenced this issue Jul 24, 2018
Fix a case where matrix parameters weren't stringified when they are passed as a first command
when creating a url tree. Fix return type in parseMatrixParams method
because it always returns {[key: string]: string}

Closes angular#23165
AlexMokin added a commit to AlexMokin/angular that referenced this issue Jul 25, 2018
Fix a case where matrix parameters weren't stringified when they are passed as a first command
when creating a url tree. Fix return type in parseMatrixParams method
because it always returns {[key: string]: string}

Closes angular#23165
AlexMokin added a commit to AlexMokin/angular that referenced this issue Jul 25, 2018
Fix a case where matrix parameters weren't stringified when they are passed as a first command
when creating a url tree. Fix return type in parseMatrixParams method
because it always returns {[key: string]: string}

Closes angular#23165
@benneq
Copy link

benneq commented Jun 5, 2019

I just experienced this issue, too.

And it's getting even worse with objects:

router.navigate([..., { foo: { bar: true } }])
// now activatedRoute.snapshot.paramMap.get('foo') === { bar: true }

// reload the page
// now activatedRoute.snapshot.paramMap.get('foo') === "[object Object]"

@r4vn
Copy link

r4vn commented Nov 5, 2019

It seems like this is not only limited to paramMap. Just encountered the very same problem with accessing queryParams after using navigate with a number.

I would definitely prefer #25095 since this solves the root issue with createUrlTree. The first pull request #23641 would only solve it for paramMap in my opinion.

@jelbourn jelbourn added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed severity3: broken labels Oct 1, 2020
jessicajaniuk pushed a commit that referenced this issue Jan 21, 2021
Fix a case where matrix parameters weren't stringified when they are passed as a first command
when creating a url tree. Fix return type in parseMatrixParams method
because it always returns {[key: string]: string}

Closes #23165

PR Close #25095
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: router effort1: hours freq2: medium help wanted An issue that is suitable for a community contributor (based on its complexity/scope). P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent state: confirmed state: has PR type: bug/fix
Projects
None yet
8 participants