angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

extract url parsing / composing into reusable service

Open vojtajina opened this issue 14 years ago • 31 comments

something like this:

compose(/path/:verb, {verb:'greet', salutation:'Hello'});
// results in URL /path/greet?salutation=Hello

$route does similar (reverse) stuff when parsing an url into params...

vojtajina avatar Jan 29 '12 21:01 vojtajina

+1 :)

witoldsz avatar Mar 21 '12 11:03 witoldsz

+1

m6w6 avatar Jul 09 '12 15:07 m6w6

+1

niklasbulitta avatar Jul 31 '12 08:07 niklasbulitta

+1

bsr203 avatar Oct 06 '12 13:10 bsr203

This is a nice idea, would it be a good idea to expose this service on $location and also allow parsing of url strings without actually changing the location (if you pull one from an iframe for example)?

iwein avatar Nov 12 '12 13:11 iwein

+1

georgiosd avatar Feb 26 '13 13:02 georgiosd

+1

dmitryevseev avatar Feb 28 '13 09:02 dmitryevseev

+1 would love to see something as powerful as http://medialize.github.com/URI.js/ rolled into $location

tanepiper avatar Feb 28 '13 10:02 tanepiper

+1

snichme avatar Mar 27 '13 19:03 snichme

+1

brettlaforge avatar Apr 18 '13 17:04 brettlaforge

+1, one of my template needs this right now to massage some urls

coli avatar Apr 29 '13 19:04 coli

+1

Leksyk avatar May 17 '13 06:05 Leksyk

+1

eyelidlessness avatar Jul 28 '13 08:07 eyelidlessness

I would like to have this. It can't be difficult to implement. $resource has the same system (Route.setUrlParams).

pahlers avatar Sep 05 '13 09:09 pahlers

Made some code to solve this problem. It would be better when this was native angular code.

https://github.com/eonlepapillon/parametrizedLocation

pahlers avatar Sep 16 '13 08:09 pahlers

:+1:

ralphschindler avatar Dec 04 '13 22:12 ralphschindler

+1

celmaun avatar Dec 19 '13 23:12 celmaun

I have been using https://github.com/fxa/uritemplate-js uses like, template = UriTemplate.parse('{?query*})'; template.expand({query: {first: 1, second: 2}}); --> "?first=1&second=2"

it is based on RFC6570

Another popular one is https://github.com/medialize/URI.js better docs, and option http://medialize.github.io/URI.js/

the only issue is the RFC uses {id} format, and angular :id. That's actually ok, depends on how you represent your string url. You can use it in route registration too like

$routeProvider .when(UriTemplate.parse('/path/{verb}).parse({}) ... `

bsr203 avatar Dec 22 '13 13:12 bsr203

+1

gauravmeena0708 avatar Jan 17 '14 18:01 gauravmeena0708

1+

sodacrackers avatar Sep 19 '14 21:09 sodacrackers