angular/javascript parsing and getting only the value of paramMap

Viewed 97

how do we get only the value from the router param map. right now the output is

 authkey:af408c30-d212-4efe-933d-54606709fa32

I only want the random "af408c30-d212-4efe-933d-54606709fa32" without the key "authkey:" how do we parse that in JavaScript ? or is there a way in angular to not include the key and just get the value. Thanks.

 this.router.paramMap.subscribe(paramMap => {
      this.authKey = paramMap.get('authkey')
    });
  • current output : authkey:af408c30-d212-4efe-933d-54606709fa32
  • desired output : af408c30-d212-4efe-933d-54606709fa32 , I want to exclude the authkey:.
2 Answers

You can just delete authKey from the retrieved string like so:

  this.authKey = paramMap.get('authkey').replace('authkey:', '')

Angular is seeing everything as the authkey parameter. This is from the way you specify parameters in your Router Module. You should do some string manipulation to remove the "authkey:".

Do this:

this.authKey = paramMap.get('authkey').replace('authkey:', '')
Related