concept $ routeprovider in category angular

appears as: $routeProvider, $routeProvider
AngularJS in Action

This is an excerpt from Manning's book AngularJS in Action.

Now that we’ve defined a route, how does it actually make it on the page? Routing with ngRoute is generally used in tandem with the ng-view directive. When a route is matched with the $routeProvider, it will look for the ng-view directive and then load and compile the template into it. In the following simplified version of the index.html page, when the page is loaded for the first time, the $routeProvider will detect that we’re at the root of the application and load the storyboard.html template into the div with ng-view="" declared on it. Prior to loading the template, it will be compiled with StoryboardCtrl so that all of the bindings are in place and render properly. Note that in the Angello application proper, a URL request for the root of the application will bring up the login screen if the user isn’t currently logged in.

  • $routeProvider is responsible for setting up the route definitions and does this in the config block of the application module.
  • Routes are primarily configured using the when method provided by $routeProvider. The when method takes two arguments: the path parameter and the route configuration object. The path parameter defines the URL pattern that the route will match against, and the route configuration object defines how the matched route is supposed to be handled.

    sitemap

    Unable to load book!

    The book could not be loaded.

    (try again in a couple of minutes)

    manning.com homepage
    test yourself with a liveTest