0

Im currently switching my application to a Single Page Application. Im having some problems configuring my ngRoute. What I want is to send a ID to the templateUrl using ?id=.

How do I do that? This my code:

app.config(["$routeProvider", function($routeProvider) {
    $routeProvider
    .when('/testing/:id', {
        templateUrl: 'templates/testing.php?id=:id'
    });
}]);

It now passes ":id" as the value for ID. Which is obvious, but how do I make it send the ":id" passed in the URL?

For example:

/testing/45

Becomes:

app.config(["$routeProvider", function($routeProvider) {
    $routeProvider
    .when('/testing/45', {
        templateUrl: 'templates/testing.php?id=45'
    });
}]);
Jacob
  • 1,933
  • 2
  • 20
  • 30

1 Answers1

3

According to the $routeProvider documentation the templateUrl can also be a function:

app.config(["$routeProvider", function($routeProvider) {
    $routeProvider
    .when('/testing/:id', {
        templateUrl: function(params) {
            return 'templates/testing.php?id=' + params.id;
        }
    });
}]);
Martijn Welker
  • 5,575
  • 1
  • 16
  • 26