angularjs - Angular: parse a URL into a route and params without following that URL? -


suppose have angular app using $routeprovider i've initialized following:

$routeprovider   .when('/foo/:var1', {     templateurl: 'templates/template-1.html',     controller: 'somecontroller'   })   .when('/bar/:var2a/:var2b', {     templateurl: 'templates/template-2.html',     controller: 'someothercontroller'   }).... 

now suppose have url , want know information route map (in particular, route parameters contains , values are) without following route. angular service such $route, $routeparams, or $routeprovider provide function will, given url, return information me?

as example, if site hosted @ example.com , called such function passing in argument 'http://example.com#/bar/2/blue' i'd return (something contains) object like

{ var2a: 2, var2b: 'blue' } 

i thought since angular's routing service has capability map urls browser's address bar route , list of params, there might way harness functionality url in application without navigating url. there? if not, there third-party library/plugin can integrate angular , this?

(in case you're curious: reason wanting if user deletes entity in application, can clear out urls in application's "recently visited" shortcut list reference entity's id user doesn't try navigate item no longer exists.)

thank helps!

$routeparams you're looking for. someothercontroller this:

.controller('someothercontroller', function($routeparams) {     var myparams = $routeparams; //{ var2a: 2, var2b: 'blue' } }); 

edit: after re-reading post, realize seem want outside of controller, $routeparams won't correct option scenario.

in case, can use $location path , associated queries, you'll need parse , assign object $location unaware of :var2a , :var2b. angular doesn't provide native function parse urls against resource structure without routing them, $routeprovider.

you should let deletion controller handle logic of removing associated content. or @ least kick off task else handle this.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -