@@ -35,6 +35,10 @@ function stateContext(el) {
35
35
* to the state that the link lives in, in other words the state that loaded the
36
36
* template containing the link.
37
37
*
38
+ * You can specify options to pass to {@link ui.router.state.$state#go $state.go()}
39
+ * using the `ui-sref-opts` attribute. Options are restricted to `location`, `inherit`,
40
+ * and `reload`.
41
+ *
38
42
* @example
39
43
* Here's an example of how you'd use ui-sref and how it would compile. If you have the
40
44
* following template:
@@ -63,12 +67,17 @@ function stateContext(el) {
63
67
* <a href="#/contacts/3" ui-sref="contacts.detail({ id: contact.id })">Bob</a>
64
68
* </li>
65
69
* </ul>
70
+ *
71
+ * <a ui-sref="home" ui-sref-opts="{reload: true}">Home</a>
66
72
* </pre>
67
73
*
68
74
* @param {string } ui-sref 'stateName' can be any valid absolute or relative state
75
+ * @param {Object } ui-sref-opts options to pass to {@link ui.router.state.$state#go $state.go()}
69
76
*/
70
77
$StateRefDirective . $inject = [ '$state' , '$timeout' ] ;
71
78
function $StateRefDirective ( $state , $timeout ) {
79
+ var allowedOptions = [ 'location' , 'inherit' , 'reload' ] ;
80
+
72
81
return {
73
82
restrict : 'A' ,
74
83
require : '?^uiSrefActive' ,
@@ -78,11 +87,21 @@ function $StateRefDirective($state, $timeout) {
78
87
var isForm = element [ 0 ] . nodeName === "FORM" ;
79
88
var attr = isForm ? "action" : "href" , nav = true ;
80
89
90
+ var options = {
91
+ relative : base
92
+ } ;
93
+ var optionsOverride = scope . $eval ( attrs . uiSrefOpts ) || { } ;
94
+ angular . forEach ( allowedOptions , function ( option ) {
95
+ if ( option in optionsOverride ) {
96
+ options [ option ] = optionsOverride [ option ] ;
97
+ }
98
+ } ) ;
99
+
81
100
var update = function ( newVal ) {
82
101
if ( newVal ) params = newVal ;
83
102
if ( ! nav ) return ;
84
103
85
- var newHref = $state . href ( ref . state , params , { relative : base } ) ;
104
+ var newHref = $state . href ( ref . state , params , options ) ;
86
105
87
106
if ( uiSrefActive ) {
88
107
uiSrefActive . $$setStateInfo ( ref . state , params ) ;
@@ -109,7 +128,7 @@ function $StateRefDirective($state, $timeout) {
109
128
if ( ! ( button > 1 || e . ctrlKey || e . metaKey || e . shiftKey || element . attr ( 'target' ) ) ) {
110
129
// HACK: This is to allow ng-clicks to be processed before the transition is initiated:
111
130
$timeout ( function ( ) {
112
- $state . go ( ref . state , params , { relative : base } ) ;
131
+ $state . go ( ref . state , params , options ) ;
113
132
} ) ;
114
133
e . preventDefault ( ) ;
115
134
}
0 commit comments