1
- function parseStateRef ( ref ) {
2
- var parsed = ref . replace ( / \n / g, " " ) . match ( / ^ ( [ ^ ( ] + ?) \s * ( \( ( .* ) \) ) ? $ / ) ;
1
+ function parseStateRef ( ref , current ) {
2
+ var preparsed = ref . match ( / ^ \s * ( { [ ^ } ] * } ) \s * $ / ) , parsed ;
3
+ if ( preparsed ) ref = current + '(' + preparsed [ 1 ] + ')' ;
4
+ parsed = ref . replace ( / \n / g, " " ) . match ( / ^ ( [ ^ ( ] + ?) \s * ( \( ( .* ) \) ) ? $ / ) ;
3
5
if ( ! parsed || parsed . length !== 4 ) throw new Error ( "Invalid state ref '" + ref + "'" ) ;
4
6
return { state : parsed [ 1 ] , paramExpr : parsed [ 3 ] || null } ;
5
7
}
@@ -43,7 +45,7 @@ function stateContext(el) {
43
45
* Here's an example of how you'd use ui-sref and how it would compile. If you have the
44
46
* following template:
45
47
* <pre>
46
- * <a ui-sref="home">Home</a> | <a ui-sref="about">About</a>
48
+ * <a ui-sref="home">Home</a> | <a ui-sref="about">About</a> | <a ui-sref="{page: 2}">Next page</a>
47
49
*
48
50
* <ul>
49
51
* <li ng-repeat="contact in contacts">
@@ -52,9 +54,9 @@ function stateContext(el) {
52
54
* </ul>
53
55
* </pre>
54
56
*
55
- * Then the compiled html would be (assuming Html5Mode is off):
57
+ * Then the compiled html would be (assuming Html5Mode is off and current state is contacts ):
56
58
* <pre>
57
- * <a href="#/home" ui-sref="home">Home</a> | <a href="#/about" ui-sref="about">About</a>
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>
58
60
*
59
61
* <ul>
60
62
* <li ng-repeat="contact in contacts">
@@ -82,7 +84,7 @@ function $StateRefDirective($state, $timeout) {
82
84
restrict : 'A' ,
83
85
require : '?^uiSrefActive' ,
84
86
link : function ( scope , element , attrs , uiSrefActive ) {
85
- var ref = parseStateRef ( attrs . uiSref ) ;
87
+ var ref = parseStateRef ( attrs . uiSref , $state . current . name ) ;
86
88
var params = null , url = null , base = stateContext ( element ) || $state . $current ;
87
89
var isForm = element [ 0 ] . nodeName === "FORM" ;
88
90
var attr = isForm ? "action" : "href" , nav = true ;
0 commit comments