If you're using ngRoute (for routing) then your application will have below configuration,
angular
.module('appApp', [
'ngRoute'
])
config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl',
controllerAs: 'main'
})
.when('/about', {
templateUrl: 'views/about.html',
controller: 'AboutCtrl',
controllerAs: 'about'
})
}
});
Now, just add a controller in this configuration just like below,
angular
.module('appApp', [
'ngRoute'
])
config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl',
activetab: 'main'
})
.when('/about', {
templateUrl: 'views/about.html',
controller: 'AboutCtrl',
activetab: 'about'
})
}
})
.controller('navController', function ($scope, $route) {
$scope.$route = $route;
});
As you've mentioned active tab in your configuration, now you just have to add active class in your <li>
or <a>
tag. Like,
ng-class="{active: $route.current.activetab == 'about'}"
Which means, whenever user click on about page, this will automatically identify the current tab and apply active css class.
I hope this helps!