Skip to content

Instantly share code, notes, and snippets.

@kpko
Created March 7, 2015 20:18
Show Gist options
  • Save kpko/bd0231ccefbaf8c415c7 to your computer and use it in GitHub Desktop.
Save kpko/bd0231ccefbaf8c415c7 to your computer and use it in GitHub Desktop.
ngRoute example with two views
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.14/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.14/angular-route.js"></script>
</head>
<body ng-app="myApp">
<a href="#/pms">PMs</a> | <a href="#/pms/5">PM Box</a>
<div ng-view></div>
<script>
var app = angular.module('myApp', ['controllers', 'ngRoute']);
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/pms/:box', {
controller: 'pmBox',
templateUrl: 'pmBox.html'
}).when('/pms', {
controller: 'pmList',
templateUrl: 'pmList.html'
}).otherwise({
redirectTo: '/pms'
});
}])
var controllers = angular.module('controllers', []);
controllers.controller('pmList', function ($scope, $routeParams) {
console.log($routeParams);
});
controllers.controller('pmBox', function ($scope, $routeParams) {
console.log($routeParams);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment