For routing, you need to use ngView and specify either template or templateUrl :
Application code.
var app = angular.module('myApp', []); app.config(function($routeProvider) { $routeProvider.when('/foo/:id', { controller: 'FooCtrl', template: '<h1>Foo {{id}}</h1>' }) .when('/bar/:test', { controller: 'BarCtrl', templateUrl: 'bartemplate.html' }) .otherwise({ controller: 'DefaultCtrl', template: '<h1>This is the default</h1>' }); }); app.controller('FooCtrl', function($scope, $routeParams) { $scope.id = $routeParams.id; }); app.controller('BarCtrl', function($scope, $routeParams) { $scope.test = $routeParams.test; }); app.controller('DefaultCtrl', function($scope){});
Homepage layout:
<div ng-app="myApp"> <a href="#/foo/123">Foo 123</a> <a href="#/bar/blah">Bar Blah</a> <a href="#">Default route</a> <hr/> <div ng-view> </div> </div>
source share