Reputation: 13616
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?
Upvotes: 2
Views: 62
Reputation: 51451
You need $routeParams
.
When defining your route:
$routeProvider
.when('/Plya/Home/:plyaId', {
templateUrl: 'plya.html',
controller: 'PlyaController'
});
In PlyaController:
module.controller('PlyaController',['$routeParams',function($routeParams) {
$scope.plyaId = $routeParams.plyaId;
}]);
Upvotes: 1
Reputation: 1042
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'
});
});
Upvotes: 1