Skip to content

Commit 388f8f8

Browse files
committed
docs(stateDirectives): first draft docs for stateDirectives
1 parent 78f4f8c commit 388f8f8

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

src/stateDirectives.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,42 @@ function stateContext(el) {
1212
}
1313
}
1414

15+
/**
16+
* @ngdoc directive
17+
* @name ui.router.state.directive:ui-sref
18+
*
19+
* @requires ui.router.state.$state
20+
* @requires $timeout
21+
*
22+
* @restrict A
23+
*
24+
* @description
25+
* A directive that binds a link (`<a>` tag) to a state. If the state has an associated
26+
* URL, the directive will automatically generate & update the `href` attribute via
27+
* the {@link ui.router.state.$state#methods_href $state.href()} method. Clicking
28+
* the link will trigger a state transition with optional parameters.
29+
*
30+
* Also middle-clicking, right-clicking, and ctrl-clicking on the link will be
31+
* handled natively by the browser.
32+
*
33+
* You can also use relative state paths within ui-sref, just like the relative
34+
* paths passed to `$state.go()`. You just need to be aware that the path is relative
35+
* to the state that the link lives in, in other words the state that loaded the
36+
* template containing the link.
37+
*
38+
* @example
39+
* <pre>
40+
* <a ui-sref="home">Home</a> | <a ui-sref="about">About</a>
41+
*
42+
* <ul>
43+
* <li ng-repeat="contact in contacts">
44+
* <a ui-sref="contacts.detail({ id: contact.id })">{{ contact.name }}</a>
45+
* </li>
46+
* </ul>
47+
* </pre>
48+
*
49+
* @param {string} ui-sref 'stateName' can be any valid absolute or relative state
50+
*/
1551
$StateRefDirective.$inject = ['$state', '$timeout'];
1652
function $StateRefDirective($state, $timeout) {
1753
return {
@@ -66,6 +102,33 @@ function $StateRefDirective($state, $timeout) {
66102
};
67103
}
68104

105+
/**
106+
* @ngdoc directive
107+
* @name ui.router.state.directive:ui-sref-active
108+
*
109+
* @requires ui.router.state.$state
110+
* @requires ui.router.state.$stateParams
111+
* @requires $interpolate
112+
*
113+
* @restrict A
114+
*
115+
* @description
116+
* A directive working alongside ui-sref to add classes to an element when the
117+
* related ui-sref directive's state is active, and removing them when it is inactive.
118+
* The primary use-case is to simplify the special appearance of navigation menus
119+
* relying on `ui-sref`, by having the "active" state's menu button appear different,
120+
* distinguishing it from the inactive menu items.
121+
*
122+
* @example
123+
* <pre>
124+
* <ul>
125+
* <li ui-sref-active="active" class="item active">
126+
* <a ui-sref="app.user({user: 'bilbobaggins'})" href="/users/bilbobaggins">@bilbobaggins</a>
127+
* </li>
128+
* <!-- ... -->
129+
* </ul>
130+
* </pre>
131+
*/
69132
$StateActiveDirective.$inject = ['$state', '$stateParams', '$interpolate'];
70133
function $StateActiveDirective($state, $stateParams, $interpolate) {
71134
return {

0 commit comments

Comments
 (0)