Created
December 12, 2012 05:56
-
-
Save jrmoran/4265198 to your computer and use it in GitHub Desktop.
Angular.JS Routes HTML5Mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = angular.module('app', []); | |
app.config(function($locationProvider, $routeProvider) { | |
$locationProvider.html5Mode(true); | |
$routeProvider | |
.when('/', { | |
templateUrl: '/partials/template1.html', // <- relative to base | |
controller: 'ctrl1' | |
}) | |
.when('/tags/:tagId', { | |
templateUrl: '/partials/template2.html', | |
controller: 'ctrl2' | |
}) | |
.when('/another', { | |
templateUrl: '/partials/template1.html', | |
controller: 'ctrl1' | |
}) | |
.otherwise({ redirectTo: '/' }); | |
}); | |
app.controller('ctrl1', function($scope){ | |
console.log('hello ctrl1'); | |
}); | |
app.controller('ctrl2', function($scope){ | |
console.log('hello ctrl2'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>Test</title> | |
<script src="components/angular-complete/angular.js" | |
type="text/javascript"></script> | |
<script src="app.js" type="text/javascript"></script> | |
</head> | |
<body ng-app='app'> | |
<div> | |
<!-- relative to base --> | |
<a href="/">Home</a> | | |
<a href="/another">another</a> | | |
<a href="/tags/1">tags/1</a> | |
</div> | |
<div ng-view></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment