Home > Net >  change the character that separates a url (Angular)
change the character that separates a url (Angular)

Time:01-19

I am obtaining the url with route.queryParams.subscribe and to separate the parameters I do it with Object.keys(params) where the latter separates them when it finds the "&". My question is, can I modify that separator, where I separate it when I find the character "$" for example and not the "&"?

The short code:

this.route.queryParams.subscribe(params => {
      this.keys = Object.keys(params);

}
Example this url www.hi.com?v+RSC60dbdNliPmWIS8mbw===&uHW0Oj81Fug5ifNoPI4rGSpH5uaejSqrADBFSQhRU4fKQF3oIAXWRqtpv3TNsi3c7GDgva1P/ozKCMFkd/DQEKqM1DBhmnV05psQ1n913EM5NjRNK53sEo60YxgVGky1bV+PB2C/1cG44b/rQPNmns7jWgQmWopQvO/CzWCD8o12HNQoINRzi/Wsg9OUhoNncPl+U8OsJWUbKutTpW/iLHa4IQRvlSG59iyj6HVC2hwXwZnXVXGfDDTX3bP4Am4HQlO61CsaidcoF6mEVGSpLg===

when you go through the code above it looks like this, where "&" is the separator

0 : v+RSC60dbdNliPmWIS8mbw===

&

1: uHW0Oj81Fug5ifNoPI4rGSpH5uaejSqrADBFSQhRU4fKQF3oIAXWRqtpv3TNsi3c7GDgva1P/ozKCMFkd/DQEKqM1DBhmnV05psQ1n913EM5NjRNK53sEo60YxgVGky1bV+PB2C/1cG44b/rQPNmns7jWgQmWopQvO/CzWCD8o12HNQoINRzi/Wsg9OUhoNncPl+U8OsJWUbKutTpW/iLHa4IQRvlSG59iyj6HVC2hwXwZnXVXGfDDTX3bP4Am4HQlO61CsaidcoF6mEVGSpLg===

So, I want to know if there is a way to modify the separator character, for example instead of "&" they pass me the url with the character "$" for example and that I separate it in the same way.

This is Angular

CodePudding user response:

why not use simple string.split("any character you want"). It will return list of array of the string splitted at("any character you want"). Or find the index using string.indexOf("any charcter you want"). Then splice the string accoordingly. You can even loop the string and return the index using array.forEach and splice it at that position

CodePudding user response:

Just in case it is useful for you, you can use this:

in the imports

import { ActivatedRoute } from '@angular/router';

in your code

const id = Number(this.activatedRoute.snapshot.paramMap.get("id"));

lets suppouse your route is this one: http://localhost:4200/identification/:id

  •  Tags:  
  • Related