Last active
December 12, 2015 09:58
-
-
Save ecowden/4755050 to your computer and use it in GitHub Desktop.
In Angular, match the current route to set the active element in a navigation bar, etc.
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
/* | |
* In your controller, create a function that compares the current location to a regular expression. | |
*/ | |
$scope.routeMatches = function (fragment) { | |
var matcher = new RegExp('^' + fragment + '$', ['i']); | |
return matcher.test($location.path()); | |
}; | |
/* | |
* In your partial, use the above function to assign an appropriate 'active' CSS class. | |
* You can also drive another directive like ng-show, etc. | |
*/ | |
<li ng-class="{active: routeMatches('/templates.*')}"> | |
<a href="#/templates/manage"><i class="icon icon-tasks bigIcon"></i> Templates</a> | |
</li> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment