Created
December 7, 2015 02:07
-
-
Save abelrgr/41ca841f3864e5c9fdef to your computer and use it in GitHub Desktop.
Angular route active by initial params
This file contains 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
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