By Arun Kumar
AngularJS provides a powerful routing mechanism that allows you to map URLs to different views and controllers in your application. One of the most common use cases for routing is to pass parameters between different views in a single page application. Here's an example of how you can use AngularJS routing with parameters:
First, you need to define your routes in your module's configuration function. For example:
In this example, we have defined two routes: the first one maps to the home view, and the second one maps to the user view with a parameter named ‘userId’.
Next, you need to define your controllers. For example:
In the ‘UserController’, we use the ‘$routeParams’ service to get the value of the userId parameter and assign it to a variable on the ‘$scope’ object.
Finally, you need to create links that navigate to your routes. For example:
In this example, clicking on the link will navigate to the user view with the ‘userId’ parameter set to ‘123’.
Note that you can also use the ‘$location’ service to navigate to your routes programmatically:
This is useful if you want to navigate to a route based on some user action, like a button click.