Skip to content

Commit 14fc2c8

Browse files
committed
Example should show how to use ui-sref-active instead of ng-class
1 parent 52155b8 commit 14fc2c8

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

sample/contacts.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
<!-- This <li> will only add the 'active' class if 'contacts.detail' or its descendants are active
99
AND if it is the link for the active contact (aka contactId) -->
10-
<li ng-repeat="contact in contacts | limitTo:2"
11-
ng-class="{ active: $state.includes('contacts.detail') && $stateParams.contactId == contact.id }">
10+
<li ng-repeat="contact in contacts | limitTo:2" ui-sref-active="active">
1211

1312
<!-- Here's a ui-sref that is also providing necessary parameters -->
1413
<a ui-sref="contacts.detail({contactId:contact.id})">{{contact.name}}</a>

sample/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
<!-- Here you can see ui-sref in action again. Also notice the use of $state.includes, which
4040
will set the links to 'active' if, for example on the first link, 'contacts' or any of
4141
its descendant states are activated. -->
42-
<li ng-class="{ active: $state.includes('contacts') }"><a ui-sref="contacts.list">Contacts</a></li>
43-
<li ng-class="{ active: $state.includes('about') }"><a ui-sref="about">About</a></li>
42+
<li ui-sref-active="active"><a ui-sref="contacts.list">Contacts</a></li>
43+
<li ui-sref-active="active"><a ui-sref="about">About</a></li>
4444
</ul>
4545

4646
<!-- Here is a named ui-view. ui-views don't have to be named, but we'll be populate this

sample/module.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ angular.module('uiRouterSample', ['ui.router', 'ngAnimate'])
66

77
// It's very handy to add references to $state and $stateParams to the $rootScope
88
// so that you can access them from any scope within your applications.For example,
9-
// <li ng-class="{ active: $state.includes('contacts.list') }"> will set the <li>
10-
// to active whenever 'contacts.list' or one of its decendents is active.
9+
// <li ui-sref-active="active }"> will set the <li> // to active whenever
10+
// 'contacts.list' or one of its decendents is active.
1111
$rootScope.$state = $state;
1212
$rootScope.$stateParams = $stateParams;
13-
}]);
13+
}]);

0 commit comments

Comments
 (0)