-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refer to current state from ui-sref (e.g. for setting url parameters). #1031
Comments
I'll be honest, we never expected the use of just a single dot (.). I'm pretty sure you can just do this though now |
I tried
Setting up a breakpoint inside of
And then the error is thrown inside |
Hmm here's the commit that added that feature. |
Indeed, it's not in the 0.2.10 yet. I have cloned the master branch, built it and took the files from the "build" folder. And now However, if put it outside of
So, when the directive is outside of a ui-view, the It could be intended/unavoidable behaviour though, I'm not sure. |
Thanks for looking into it. Hopefully we'll take a look soon. |
We're also missing this feature. Currently there's no clean way to link back to the current state without query parameters (remove parameters and trigger state change). |
+1 |
I can confirm that this works in 0.2.11 - no more error. However, it seems like the page is still reloaded. |
I just tried this out and while it works perfectly when you load the page, if I change a state (e.g. from 'dashboard' to 'explore'), it still tries to redirect the user to |
+1 on this. Pretty pressing for handling user-friendly async pagination. |
+1 |
2 similar comments
+1 |
+1 |
+1 using edit: Spoke too soon. I got this to work. Remove the |
Okay, so sounds like maybe the |
Pretty sloppy, but it should give you an idea. The expected outcome is for it to stay on either the color or size route when you click on a different item. http://plnkr.co/edit/fARlus6UmokOsdRxbaoS |
I just updated the plunk with AngularJS 1.3.15 and ui-router 0.3.14 and the href tag still does not get updated on state change. http://plnkr.co/edit/8jZCbEVuoO4srwU8fIY5?p=preview |
Okay, I see the issue. Should be able to patch it later today. |
@nateabele any luck? |
Confirm I am able to switch between items in my current state by changing one param value using
angular 1.3.14, angular-ui-router 0.2.13 |
This only works the first time.
On later changes, the itemId is correct, but the suffix part of the pageload URL is used. Angular 1.3.15, angular-ui-router 0.2.15. |
This seems to work for me:
|
@RuleB I later found what you said: I was mistaken, it only worked the first time, but not on later changes. Ended up with a workaround involving marking some states as needing reload using the data object ( Seems to be working as needed (~2 months use) but feels like a fragile workaround. |
I would like to submit a possible solution for this issue.
Change details: In the ui-sref directive code:
And then watch for the state change to update the href when current state changes:
|
+1 for handling "." |
+1 for an elegant notation such as "." to refer to the current state. Has there been any further progress on this? |
+1 for the dot proposal! |
+1 for handling "." |
+1 for the dot proposal! |
+1 |
2 similar comments
+1 |
+1 |
Anyone who would like to submit a PR to implement this is welcome to do so. |
Submitted my solution |
@shprota works for me, thanks! |
It would be great if you could merge @shprota's PR. |
I've done some analysis on this. We can't use "." cannot refer to the currently active state, and we already have syntax for parameter-only ui-srefs, but it is broken in some cases. I am fixing the existing parameter-only ui-sref syntax so it updates when the state changes. i.e., Here's an example which has two states: home and home.foo. There are both styles of ui-sref links, and their equivalent ui-state links. Note the difference in behavior (when the current state is home.foo) between links with a "." links without one. http://plnkr.co/edit/JzuxiVezaAaW697JYE8o?p=preview here is @zschiffelbein plunker with the new changes: http://plnkr.co/edit/Vs8FcVn1bQO60vo8HHNl?p=preview |
- ui-sref with only parameter values should always refer to the current state (not context sensitive)
The documentation explicitly states "You can also use relative state paths within ui-sref, just like the relative paths passed to $state.go()." However, even though we are able to refer to the current state with
$state.go('.', {foo: 'bar'})
it doesn't seem to work when usingui-sref
directive. I naively triedui-sref=".({foo:'bar'})"
which failed.Of course it is possible to wire up
ng-click
and$state.go
, but that leaves us with href-less anchors, which is not very useful from the user perspective.I've ventured a related question on stackoverflow in case somebody had figured it out already. But it appears not to be the case.
Does this functionality exist already (maybe I just missed/misused it)? If not, should it be implemented?
The text was updated successfully, but these errors were encountered: