From 71cad3d636508b5a9fe004775ad1f1adc0c80c3e Mon Sep 17 00:00:00 2001 From: Tima Maslyuchenko Date: Thu, 6 Mar 2014 09:32:18 +0200 Subject: [PATCH] feat(uiSref): extend syntax for ui-sref add possibility to pass params to current state without entering state name --- src/stateDirectives.js | 14 ++++++++------ test/stateDirectivesSpec.js | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/stateDirectives.js b/src/stateDirectives.js index 2dd89627a..5090d576f 100644 --- a/src/stateDirectives.js +++ b/src/stateDirectives.js @@ -1,5 +1,7 @@ -function parseStateRef(ref) { - var parsed = ref.replace(/\n/g, " ").match(/^([^(]+?)\s*(\((.*)\))?$/); +function parseStateRef(ref, current) { + var preparsed = ref.match(/^\s*({[^}]*})\s*$/), parsed; + if (preparsed) ref = current + '(' + preparsed[1] + ')'; + parsed = ref.replace(/\n/g, " ").match(/^([^(]+?)\s*(\((.*)\))?$/); if (!parsed || parsed.length !== 4) throw new Error("Invalid state ref '" + ref + "'"); return { state: parsed[1], paramExpr: parsed[3] || null }; } @@ -43,7 +45,7 @@ function stateContext(el) { * Here's an example of how you'd use ui-sref and how it would compile. If you have the * following template: *
- * Home | About
+ * Home | About | Next page
  * 
  * 
  * 
* - * Then the compiled html would be (assuming Html5Mode is off): + * Then the compiled html would be (assuming Html5Mode is off and current state is contacts): *
- * Home | About
+ * Home | About | Next page
  * 
  *