@@ -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
* <pre>
40
44
* <a ui-sref="home">Home</a> | <a ui-sref="about">About</a>
@@ -44,12 +48,17 @@ function stateContext(el) {
44
48
* <a ui-sref="contacts.detail({ id: contact.id })">{{ contact.name }}</a>
45
49
* </li>
46
50
* </ul>
51
+ *
52
+ * <a ui-sref="home" ui-sref-opts="{reload: true}">Home</a>
47
53
* </pre>
48
54
*
49
55
* @param {string } ui-sref 'stateName' can be any valid absolute or relative state
56
+ * @param {Object } ui-sref-opts options to pass to {@link ui.router.state.$state#go $state.go()}
50
57
*/
51
58
$StateRefDirective . $inject = [ '$state' , '$timeout' ] ;
52
59
function $StateRefDirective ( $state , $timeout ) {
60
+ var allowedOptions = [ 'location' , 'inherit' , 'reload' ] ;
61
+
53
62
return {
54
63
restrict : 'A' ,
55
64
require : '?^uiSrefActive' ,
@@ -59,11 +68,21 @@ function $StateRefDirective($state, $timeout) {
59
68
var isForm = element [ 0 ] . nodeName === "FORM" ;
60
69
var attr = isForm ? "action" : "href" , nav = true ;
61
70
71
+ var options = {
72
+ relative : base
73
+ } ;
74
+ var optionsOverride = scope . $eval ( attrs . uiSrefOpts ) || { } ;
75
+ angular . forEach ( allowedOptions , function ( option ) {
76
+ if ( option in optionsOverride ) {
77
+ options [ option ] = optionsOverride [ option ] ;
78
+ }
79
+ } ) ;
80
+
62
81
var update = function ( newVal ) {
63
82
if ( newVal ) params = newVal ;
64
83
if ( ! nav ) return ;
65
84
66
- var newHref = $state . href ( ref . state , params , { relative : base } ) ;
85
+ var newHref = $state . href ( ref . state , params , options ) ;
67
86
68
87
if ( uiSrefActive ) {
69
88
uiSrefActive . $$setStateInfo ( ref . state , params ) ;
@@ -90,7 +109,7 @@ function $StateRefDirective($state, $timeout) {
90
109
if ( ! ( button > 1 || e . ctrlKey || e . metaKey || e . shiftKey || element . attr ( 'target' ) ) ) {
91
110
// HACK: This is to allow ng-clicks to be processed before the transition is initiated:
92
111
$timeout ( function ( ) {
93
- $state . go ( ref . state , params , { relative : base } ) ;
112
+ $state . go ( ref . state , params , options ) ;
94
113
} ) ;
95
114
e . preventDefault ( ) ;
96
115
}
0 commit comments