Update:
This answer was for a much older release of Ui-Router. For the more recent releases (0.2.5+), please use the helper directive ui-sref-active
. Details here.
Original Answer:
Include the $state service in your controller. You can assign this service to a property on your scope.
An example:
$scope.$state = $state;
Then to get the current state in your templates:
$state.current.name
To check if a state is current active:
$state.includes('stateName');
This method returns true if the state is included, even if it's part of a nested state. If you were at a nested state, user.details
, and you checked for $state.includes('user')
, it'd return true.
In your class example, you'd do something like this:
ng-class="{active: $state.includes('stateName')}"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…