Skip to content

Instantly share code, notes, and snippets.

@abelrgr
Created December 7, 2015 02:07
Show Gist options
  • Save abelrgr/41ca841f3864e5c9fdef to your computer and use it in GitHub Desktop.
Save abelrgr/41ca841f3864e5c9fdef to your computer and use it in GitHub Desktop.
Angular route active by initial params
javascript:
.directive('navbarCustom', ['$location', function($location) {
return {
restrict: 'C',
link: function(scope, elem, attrs) {
scope.checkActive = function(param) {
if (param == scope.active1) {
return true;
};
};
scope.$on('$routeChangeSuccess', function() {
var route = $location.path().split('/');
scope.active1 = route[1];
});
}
};
}])
HTML:
<ul class="nav navbar-nav navbar-right">
<li ng-class="{'active': checkActive('') }"><a
href="#/">Inicio</a></li>
<li ng-class="{'active': checkActive('hosting') }"><a
href="#/hosting">Web Hosting</a></li>
<li ng-class="{'active': checkActive('proyectos') }"><a
href="#/proyectos">Proyectos</a></li>
<li ng-class="{'active': checkActive('utilidades') }"><a
href="#/utilidades">Utilidades</a></li>
<li ng-class="{'active': checkActive('contactenos') }"><a
href="#/contactenos">Contactenos</a></li>
<!-- <li><a href="#/nosotros">Compras Web</a></li> -->
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment