Practical AngularJS Part 2 - Sample 6

An example of views in angular.

by Dave Kerr

HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular-route.js"></script>
<div ng-app="app">
    <p><a href="#/home">Home</a> | <a href="#/contact">Contact</a></p>
    <ng-view></ng-view>
</div>

JavaScript

//  Create our app.
var app = angular.module('app', ['ngRoute']);
 
//  Configure the route provider.
app.config(function($routeProvider, $locationProvider) {
    $routeProvider.
      when('/home', {
        template: '<h2>Home</h2>',
        controller: 'HomeController'
      }).
      when('/contact', {
        template: '<h2>Contact</h2>',
        controller: 'ContactController'
      }).
      otherwise({
        redirectTo: '/home'
      });
});
app.controller('ShowOrderController', function() {
});
app.controller('ContactController', function() {
    debugger;
});