Skip to content

Instantly share code, notes, and snippets.

@Netcelal
Created October 12, 2012 20:32
Show Gist options
  • Save Netcelal/3881341 to your computer and use it in GitHub Desktop.
Save Netcelal/3881341 to your computer and use it in GitHub Desktop.
Page navigation bar in AngularJS
<div class="well sidebar-nav" ng-app="navList">
<ul class="nav nav-list" ng-controller="navCtrl">
<li ng-class="navClass('home')"><a href='#/home'>Home</a></li>
<li ng-class="navClass('about')"><a href='#/about'>About Us</a></li>
<li ng-class="navClass('contact')"><a href='#/contact'>Contact Us</a></li>
</ul>
</div>
var navList = angular.module('navList', []);
navList.controller('navCtrl', ['$scope', '$location', function ($scope, $location) {
$scope.navClass = function (page) {
var currentRoute = $location.path().substring(1) || 'home';
return page === currentRoute ? 'active' : '';
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment