-
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
Dynamic ui-sref in directive #395
Comments
Correct. |
Technically difficult, or just not a priority? |
More of an API design consideration. |
Ah ok. Is there an official guideline as how one would implement dynamic links then? I'm guessing a function that calls the full |
Yeah, you can use |
Cool, thanks! |
No worries. If there gets to be a big enough demand for this, we'll come back around and design a proper implementation, so I'll keep your notes here in mind. |
👍 |
this directive was in this repository before v0.2.0, but it was not a part of the release installed with bower. I found it, used it and faced this bug. I fixed this issue for myself and thought it was no official part of ui-router. Today - using v0.2.0 I faced the need of this feature again and I found my ui-sref.js in my git repository. Here is the code I used earlier:
There could be some bugs, because I used it only once in testproject and It never got into production. |
@maklemenz Um, this isn't a bug. Also, that implementation doesn't even work for HTML5 mode. |
@nateabele Yes, I said my code will not be production ready (or will contain bugs). It feels like a bug, because you cannot use this directive in any more complex application where you generalize things with directives. You need to resolve the url yourself with the services. For me this means I cannot use this directive in 99.9% of all my applications and need to do everything that directive is made for by hand. that feels like a bug IMHO. |
@maklemenz Please see my notes on #139, specifically:
|
@nateabele I see. A design decision. Personally I think |
Just wanted to say I came here looking for the exact same thing. I'll work something else out for now. |
I was looking for the same exact feature, and wondering why it wasn't working... @nateabele Actually, I can't see why you think this is out-of-scope for a routing service. My use case is pretty straight forward.
And I would love to call it back with something like:
It doesn't look out-of-scope to me, it's a "simple" route back to the caller |
I come across this issue when I am refactoring out all my In my scenario I store the state name in a variable in the scope, which is the same as @dmatteo mentioned. I guess I just cannot remove the URL helper I wrote that invokes |
So this has roughly +4 or 5 at this point... I think its worthy of reopening. |
My current solution is to create a new directive called <a sref-name="stateNameVariableInScope" sref-param="{...}">...</a>
By separating the state name and state params, it looks slightly better than interpolation (though I think there is nothing bad with interpolation.) |
Currently facing a need for this right now. |
Just hit a need for this. Adding a function on my model that uses |
+1 for this. |
+1 This would be unbelievably useful for creating data driven nav menus. update 2014-01-19: this actually works fine -- as expected. see html snippet
..... |
+1 I ran into this issue too today |
+1...totally. |
+1 (jlmagee) Is right on the money ! breadcrumbs & navigation toolbars indeed require this feature ! |
So hold on... does it work or doesn't it? @jlmagee is saying it does above: #395 (comment). Can anyone else validate that it works? |
I pretty much do this in every single app I ever build: app.run(function($rootScope, $state) {
$rootScope.$state = $state;
// or
$rootScope.go = $state.go.bind($state);
}) |
Ok, thanks. That's more reasonable |
@ProLoser that technique might create problems for those that use prerendering for crawlers. Besides that I've personally not encountered a project thats required more than around 20 active |
@homerjam honestly dude, you're going to have way bigger issues when dealing with crawlers. I just don't think it's worth the overhead for something you only interact with ONCE and is only relevant during interaction. If it REALLY is important for you to have sexy urls you could do |
And what about a different directive, something like ui-sref-dynamic? It's the same as ng-bind-once or solutions like those. |
Nate mentioned some API considerations. I'm not sure what those were so until I hear what they are, If performance is the concern, I bet we could find a way to make the common case fast, such as not observing if we know the value cant change. That said, the workarounds are simple and easy, but it would be nice to have consistent linking mechanism in a UI-Router app. |
I would opt for a separate directive, i.e.: <div ng-controller="FooController">
<a ui-state="state" ui-state-params="params" ui-state-opts="{ absolute: true }">
Link
</a>
</div> function FooController($scope) {
angular.extend($scope, {
state: "person.view",
params: { id: 1138 }
});
} No ugly syntax. No one-off micro-grammars. No complicated parsing rules. No inconsistent behavior. No degraded performance for default use cases. If anyone would like to implement this, PRs are now being accepted. Please remember to consult the contributor guidelines. |
+1 |
It works for me on version 0.2.11:
|
+1 for the feature If you have nested views and stated, you solved it by adding the $state to the scope. The view : |
+1 i'd need that too. |
+1 |
+1 I need that too |
+1 is this implemented already? |
+1 |
2 similar comments
+1 |
+1 |
If anyone would like to implement this, please submit a PR and reference this issue, thanks. |
- Refactor StateRefDirective for better modularity - Drop key restrictions on ui-sref-opts - Improves performance over prior implementation with no extra $eval()’s Fixes angular-ui#395, angular-ui#900, angular-ui#1932
I've written a breadcrumb directive which takes an array of crumbs, each with a name and sref property. I'm trying to bind the
ui-sref
directive ($StateRefDirective
) to use the evaluated attribute, but it's not working. When theui-sref
directive'slink
function is called, theattrs.uiSref
value isundefined
, but immediately after the running of the function becomes available as the correct value.Inside the
$StateRefDirective
link
method, loggingattrs
givesRunning the same log after a 100ms timeout gives:
Am I doing something wrong, or are dynamic
ui-sref
attributes not supported?Note: Running
v0.2.0
The text was updated successfully, but these errors were encountered: