In AngularJS, you can pass parameters through routes using the $routeProvider
service by including a colon (:
) followed by the parameter name in the URL path.
$routeProvider
.when('/user/:userId', {
templateUrl: 'user.html',
controller: 'UserController'
});
In this example, :userId
is a route parameter. You can access it in your controller using $routeParams
:
app.controller('UserController', function($scope, $routeParams) {
$scope.userId = $routeParams.userId;
});
This allows you to dynamically handle data based on the URL, such as loading a specific userโs profile.
If you're developing or maintaining AngularJS applications and need expert help, check out our AngularJS development services to learn how we can support your business with scalable, clean, and efficient solutions.