Created
September 26, 2014 16:40
-
-
Save just-boris/a9746e8f6592e9c66ed6 to your computer and use it in GitHub Desktop.
Class on route
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
| //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