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

URL is not a standard javascript class, so this really should be a core angular service, to avoid many duplicates of similar logic.

johncrim avatar Nov 08 '15 22:11 johncrim

+1

STOpandthink avatar Jan 14 '16 17:01 STOpandthink

+1

tools4origins avatar Feb 24 '16 13:02 tools4origins

+1. Or more.

andy-rush avatar Mar 01 '16 15:03 andy-rush

+1 The valid use case I have is, I need to check the length of url generated for GET request before making request, as some urls generated are too long due to request params has list that grows big.

chetankhilosiya avatar Apr 13 '17 12:04 chetankhilosiya

Is there any progress on this one?

pashchuk avatar Jan 26 '18 10:01 pashchuk

+1

panlina avatar Mar 05 '18 09:03 panlina

OK, so we have agreed to expose the setUrlParams function as a service on the ngResource module. We do not want to add it to the core AngularJS module as it would add unnecessary code to that file.

petebacondarwin avatar Mar 05 '18 22:03 petebacondarwin

We've decided not to add this after all, as only a small number of people would benefit from the option to manipulate url params in resource. And we don't want to expose a general url composition service in AngularJS as core should cater specifically to the needs of the framework.

Narretz avatar Jul 04 '18 09:07 Narretz

@gilbsgilbs - since we are entering LTS mode the code for manipulating the URLs internally in AngularJS is not going to change (or at least it is very very unlikely to change). So it is pretty easy and safe to copy the code from angular-resource.js and reuse it in your own applications.

petebacondarwin avatar Jul 05 '18 07:07 petebacondarwin

@petebacondarwin that's a neat suggestion. Thank you very much. I will opt for this (and I totally understand the decision).

gilbsgilbs avatar Jul 05 '18 08:07 gilbsgilbs