Skip to content
Advertisement

How to encode a URL in an AngularJS controller

I’m having a bit of a problem trying to submit URLs that I’m building dynamically in my AngularJS controller code, and then encoding using encodeURIComponent()

Here’s a URL example built out dynamically (prior to encoding, and will not submit via Fiddler):

JavaScript

Same URL, manually encoded with %20 (which does submit to API layer via Fiddler):

JavaScript

However, encoding via encodeURIComponent() does not submit to my API layer via Fiddler. Here’s the coded URL:

JavaScript

and my angular controller code which builds out the URL and submit to datacontext layer :

JavaScript

If you can provide some advice on the best way to encode URLs, that would be great.

thank you.

Bob

Advertisement

Answer

Try

JavaScript

or may be you can just regex replace space with %20

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement