@@ -24,40 +24,40 @@ function stateContext(el) {
24
24
* @restrict A
25
25
*
26
26
* @description
27
- * A directive that binds a link (`<a>` tag) to a state. If the state has an associated
28
- * URL, the directive will automatically generate & update the `href` attribute via
29
- * the {@link ui.router.state.$state#methods_href $state.href()} method. Clicking
30
- * the link will trigger a state transition with optional parameters.
27
+ * A directive that binds a link (`<a>` tag) to a state. If the state has an associated
28
+ * URL, the directive will automatically generate & update the `href` attribute via
29
+ * the {@link ui.router.state.$state#methods_href $state.href()} method. Clicking
30
+ * the link will trigger a state transition with optional parameters.
31
31
*
32
- * Also middle-clicking, right-clicking, and ctrl-clicking on the link will be
32
+ * Also middle-clicking, right-clicking, and ctrl-clicking on the link will be
33
33
* handled natively by the browser.
34
34
*
35
- * You can also use relative state paths within ui-sref, just like the relative
35
+ * You can also use relative state paths within ui-sref, just like the relative
36
36
* paths passed to `$state.go()`. You just need to be aware that the path is relative
37
- * to the state that the link lives in, in other words the state that loaded the
37
+ * to the state that the link lives in, in other words the state that loaded the
38
38
* template containing the link.
39
39
*
40
40
* You can specify options to pass to {@link ui.router.state.$state#go $state.go()}
41
41
* using the `ui-sref-opts` attribute. Options are restricted to `location`, `inherit`,
42
42
* and `reload`.
43
43
*
44
44
* @example
45
- * Here's an example of how you'd use ui-sref and how it would compile. If you have the
45
+ * Here's an example of how you'd use ui-sref and how it would compile. If you have the
46
46
* following template:
47
47
* <pre>
48
48
* <a ui-sref="home">Home</a> | <a ui-sref="about">About</a> | <a ui-sref="{page: 2}">Next page</a>
49
- *
49
+ *
50
50
* <ul>
51
51
* <li ng-repeat="contact in contacts">
52
52
* <a ui-sref="contacts.detail({ id: contact.id })">{{ contact.name }}</a>
53
53
* </li>
54
54
* </ul>
55
55
* </pre>
56
- *
56
+ *
57
57
* Then the compiled html would be (assuming Html5Mode is off and current state is contacts):
58
58
* <pre>
59
59
* <a href="#/home" ui-sref="home">Home</a> | <a href="#/about" ui-sref="about">About</a> | <a href="#/contacts?page=2" ui-sref="{page: 2}">Next page</a>
60
- *
60
+ *
61
61
* <ul>
62
62
* <li ng-repeat="contact in contacts">
63
63
* <a href="#/contacts/1" ui-sref="contacts.detail({ id: contact.id })">Joe</a>
@@ -76,8 +76,8 @@ function stateContext(el) {
76
76
* @param {string } ui-sref 'stateName' can be any valid absolute or relative state
77
77
* @param {Object } ui-sref-opts options to pass to {@link ui.router.state.$state#go $state.go()}
78
78
*/
79
- $StateRefDirective . $inject = [ '$state' , '$timeout' ] ;
80
- function $StateRefDirective ( $state , $timeout ) {
79
+ $StateRefDirective . $inject = [ '$state' , '$timeout' , '$q' ] ;
80
+ function $StateRefDirective ( $state , $timeout , $q ) {
81
81
var allowedOptions = [ 'location' , 'inherit' , 'reload' , 'absolute' ] ;
82
82
83
83
return {
@@ -134,7 +134,12 @@ function $StateRefDirective($state, $timeout) {
134
134
if ( ! ( button > 1 || e . ctrlKey || e . metaKey || e . shiftKey || element . attr ( 'target' ) ) ) {
135
135
// HACK: This is to allow ng-clicks to be processed before the transition is initiated:
136
136
var transition = $timeout ( function ( ) {
137
- $state . go ( ref . state , params , options ) ;
137
+ var $transition = $state . go ( ref . state , params , options ) ;
138
+ if ( $transition && attrs . uiSrefOn ) {
139
+ scope . $eval ( attrs . uiSrefOn , {
140
+ $transition : $q . when ( $transition )
141
+ } ) ;
142
+ }
138
143
} ) ;
139
144
e . preventDefault ( ) ;
140
145
0 commit comments