2

Rewording my previous question, I have this route which gives me something like this /order-screen/store/1/London

 {
    path: 'order-screen/store/:storeId/:storeLocation',
    component: OrderComponent
  }

When I try to get the storeLocation using this.route.params it returns an error of NaN. I want to get the location London, not sure if .params is the right one to use.

this.routeSub = this.route.params.subscribe(params => {
  this.storeLocation = +params['storeLocation'];
  console.log('Location >> ', this.storeLocation);
})
0

1 Answer 1

6

Just remove the + from before your params. So..

this.routeSub = this.route.params.subscribe(params => {
this.storeLocation = params['storeLocation'];
  console.log('Location >> ', this.storeLocation);
})

The + will convert a string to a number and since "London" is not a number you got the NaN error

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah figured that earlier, somehow my comment to my own question didn't post. But I will give your answer a check :)
Glad you didn't get stuck there for too long and figured it out on your own :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.