O'Reilly logo

Learning Web Development with Bootstrap and AngularJS by Stephen Radford

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating basic routes

As we've already discovered, in order to configure the router within AngularJS, a module is required. In Chapter 3, Filters, we created one to allow us to build a custom filter. We can utilize this same module to build our routes.

Routes are created within the config method of our application's module:

angular.module('contactsMgr', ['ngRoute'])
.config(function($routeProvider){
    
})

The method accepts an anonymous function that we can inject our required $routeProvider service into. This service has just two methods: when and otherwise. To add a route, we use the when method, which accepts two parameters: the path as a string and options for the route as an object:

angular.module('contactsMgr', ['ngRoute']) .config(function($routeProvider){ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required