How to use $routeProvider with $_GET Parameters

I’m new with the angularjs and I want your help. I’m trying to include the $routeProvider into my project in order to use templating system.

     $routeProvider.when('/admin.php?page=all_transactions', {
                templateUrl : 'pages/home.html',
                controller  : 'TransactionsController'
        });

I saw that most of the examples i found the url of .when had the following format /route1/:param for urls like #/route1/12345

Read More

Because I’m using the angular in wordpress admin page I want the .when to work with $_GET parameters like the one I gave with the example code.

The depth of parameters I want it to be up to 3 and ignore any other parameters.

Does anyone know how I can do it?

Related posts

Leave a Reply

1 comment

  1. is it enough for u to know, that the params are there? Or do u need explicit values.
    If the params are enough u could follow this example: URL Routing with Query Parameters

    url: "/contacts?myParam"
    // will match to url of "/contacts?myParam=value"
    

    If you need to have more than one, separate them with an ‘&’:

    url: "/contacts?myParam1&myParam2" 
    // will match to url of "/contacts?myParam1=value1&myParam2=wowcool"
    

    Hope this helps.

    Edit: For accessing the values u can do the following: Accessing query parameter values

    Also can get other arbitrary params in the query string form /view/1/2?other=12 with $routeParams.other – DavidC Aug 17 ’14 at 21:04

    OR:
    While routing is indeed a good solution for application-level URL parsing, you may want to use the more low-level $location service, as injected in your own service or controller:

    var paramValue = $location.search().myParam; 
    

    This simple syntax will work for http://example.com/path?myParam=someValue. However, only if you configured the $locationProvider in the html5 mode before:

    $locationProvider.html5Mode(true);
    

    Otherwise have a look at the http://example.com/#!/path?myParam=someValue “Hashbang” syntax which is a bit more complicated, but have the benefit of working on old browsers (non-html5 compatible) as well.