AngularJS : Routing
In previous tutorial we saw AngularJS Controllers and $scope. In this article we will understand another useful feature of AngularJS called “Routing”. It helps us to divide a single page application (SPA) in multiple views. Dividing a SPA in multiple views helps in logically dividing the app and making it more manageable. Routing in angular application is taken care by a service provider known as “$routeProvider”. The $routeProvider is configured in app module's config() function. $routeProvider provides two following methods
1 .when() : which matches a pattern
2 .otherwise() : otherwise() method to define a default route.
Route.html
- <h1>List of friends</h1>
- {{ message }}
- <h1>Add new friend</h1>
- {{ message }}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular-route.min.js"></script>
Now we have created an angular app “MyApp” using angular.module method. We have used config() method to configure $routeProvider. We have added routes for List and Add. For each route we have defined template url and controller.
We have assigned values in $scope object for each controller.


We can also the parameter with route. Suppose we want to a FriendId to show the details then we have to add a route as
- when('/Show/:id', {
- templateUrl: 'Views/Show.html',
- controller: 'ShowController'
- }).
- App.controller('ShowController', function($scope, $routeParams) {
- $scope.friendId = $routeParams.id;
- $scope.name = "Rahul";
- });
- when('/Show/:id', {
- template: 'friend id:{{ friendId }} friend Name: {{ name }}',
- controller: 'ShowController'
- }).



Vignesh ManiTOP 100Posted Aug 17, 2016, 3:57 AM EDT
Good one
Ramesh PalaniappanPosted Aug 16, 2016, 4:30 AM EDT
Nice Video
Debasis SahaTOP 100Posted Aug 15, 2016, 8:57 PM EDT
Nice One..
Nitin PanditTOP 100Posted Aug 15, 2016, 7:53 PM EDT
Really nice and so much easy to understandable just awesome :)