AngularJS Routing
by Daniel Clasen
HTML
<script type="text/ng-template" id="home.html">
<h1>Home</h1>
</script>
<script type="text/ng-template" id="blog.html">
<h1>Blog</h1>
</script>
<div>
AngularJS Routing
<div>
<a href="#/home">Home</a>
<a href="#/blog">Blog</a>
</div>
<div ng-view></div>
</div>
JavaScript
var routingExample = angular.module('Example.Routing', []);
routingExample.controller('HomeController', function ($scope) {});
routingExample.controller('BlogController', function ($scope) {});
routingExample.config(function ($routeProvider) {
$routeProvider.
when('/home', {
templateUrl: 'home.html',
controller: 'HomeController'
}).
when('/blog', {
templateUrl: 'blog.html',
controller: 'BlogController'
}).
otherwise({
redirectTo: '/home'
});
});