Reputation: 149
I'm working in a component which receive a queryParam with two values:
Example: http://localhost:4200/start/setup-employee?c=RCS8KR8J&email=test$#[email protected]
The problem is if I get the queryParams the param "c" is ok, but the param "email" only return "test$" because the # cut the param. Any idea how to solve this? I see that I can get the rest in the fragment, but maybe is another good solution.
Upvotes: 0
Views: 1553
Reputation: 1635
When ever passing the special ml characters in the url make use of the encodeURIComponent function before passing the value like this
encodeURIComponent("test$#[email protected]");
Output
test%24%23myaddress%40gmail.com
And do the decide then use the value
decodeURIComponent("test%24%23myaddress%40gmail.com");
Output
test$#[email protected]
This way no cutting of query parama will happen. This way you can be safe with all the special characters blocks anytime in the query params.
Upvotes: 2
Reputation: 9
This isn't Angular's fault. This is just a behavior of how the urls is handled when we do a http request, some characters can't be used in a queryParam value because that character already has a reserved meaning. Try to replace # with he's hashed value where you assign the value like: .replace('&', '%26');
.
Upvotes: 1