Skip to content

Instantly share code, notes, and snippets.

@martindale
Created July 6, 2013 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martindale/5940374 to your computer and use it in GitHub Desktop.
Save martindale/5940374 to your computer and use it in GitHub Desktop.
var Site = angular.module('secret-project', []);
angular.element(document).ready(function() {
angular.bootstrap(document, [function($compileProvider, $locationProvider, $provide){
$locationProvider.html5Mode(true);
}]);
});
Site.config(function ($routeProvider) {
$routeProvider
.when('/page/:slug', {templateUrl: 'partials/page.html', controller: 'RouteController'})
.otherwise({redirectTo: '/page/home'});
});
function AppController ($scope, $rootScope, $http) {
// Load pages on startup
$http.get('/pages.json').success(function (data) {
$rootScope.pages = data;
});
// Set the slug for menu active class
$scope.$on('routeLoaded', function (event, args) {
$scope.slug = args.slug;
});
}
function RouteController ($scope, $rootScope, $routeParams) {
// Getting the slug from $routeParams
var slug = $routeParams.slug;
$scope.$emit('routeLoaded', {slug: slug});
$scope.page = $rootScope.pages[slug];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment