How do I get a variable from the path?

advertisements

I have this path:

http://localhost:1234/#/Plya/Home

Sometimes the path above can have variable:

http://localhost:1234/#/Plya/Home/1234

My question is how to get variable 1234 from the path using angularJS?


You must use in your controller $routeParams that contains the variable:

$scope.id = $routeParams.userName;

In the routing you have to specify:

app.config(function ($routeProvider) {
    $routeProvider.when('/configUser/:userName', {
            templateUrl: '/app/views/configUser.html',
            controller: 'configUserController'
        });
});