Beginning AngularJS

(WallPaper) #1

Chapter 8 ■ Organizing Views


Table 8-1 shows a few of the $location services methods acting on various URLs, though right now, we are
mainly concerned with the path() method. It is this method that the routing system is using to determine whether or
not the routes we configure are a match. Let’s focus our attention back on index.html, or, more specifically, the route
configuration we have in place. Listing 8-9 shows this portion of the file.


Listing 8-9. The index.html Route Configuration


var app = angular.module('app', ['ngRoute']);
app.config(function ($routeProvider) {


// configure the routes
$routeProvider
.when('/', {
// route for the home page
templateUrl: 'pages/home.html',
controller: 'homeController'
})
.when('/pages/about', {
// route for the about page
templateUrl: 'pages/about.html',
controller: 'aboutController'
})
.when('/pages/contact/', {
// route for the contact page
templateUrl: 'pages/contact.html',
controller: 'contactController'
})


Table 8-1. How the $location Service Works with URLs


http://localhost:63342/index.html#/


$location.path() /


$location.url() /


$location.absUrl() http://localhost:63342/index.html#/


http://localhost:63342/index.html#/about


$location.path() /about


$location.url() /about


$location.absUrl() http://localhost:63342/index.html#/about


http://localhost:63342/index.html#/contact?someParam=someValue


$location.path() /contact


$location.url() /contact?someParam=someValue


$location.absUrl() http://localhost:63342/index.html#/
http://localhost:63342/index.html#/contact?someParam=someValue

Free download pdf