Skip to content

Instantly share code, notes, and snippets.

@just-boris
Created September 26, 2014 16:40
Show Gist options
  • Select an option

  • Save just-boris/a9746e8f6592e9c66ed6 to your computer and use it in GitHub Desktop.

Select an option

Save just-boris/a9746e8f6592e9c66ed6 to your computer and use it in GitHub Desktop.
Class on route
//update class on route change
angular.module('myApp', ['ngRoute']).run(function($rootScope, $rootElement) {
var view = angular.element($rootElement[0].querySelector('[ng-view]'));
$rootScope.$on('$routeChangeSuccess', function(event, to, from) {
view.removeClass(from.viewClass).addClass(to.viewClass);
});
});
//define classes while define routes
angular.module('myApp').config(function($routeProvider) {
$routeProvider.when('/', {
controller: 'HomeCtrl',
templateUrl: 'home.html',
viewClass: 'view_home'
}).when('/page/:id', {
controller: 'PageCtrl',
templateUrl: 'page.html',
viewClass: 'view_page'
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment