-
Notifications
You must be signed in to change notification settings - Fork 3k
Directive using short-hand syntax to generate hrefs #16
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
Comments
We need to remember Parameters as part of this... Like in the state that i Bound to '/item/:itemId'... |
This needs more explanation, what is going on in your code example? |
Like the state defined in the example:
We can't just go at
or
In any case, contacts.detail.item requires an input parameter which is
That would go in line with what $IgorMinar said in #7 :
Or have I completely misunderstood where you where going with this feature?... |
Oh ok, its like href but for states. In case you want to navigate to a state (without using urls) via a directive. So I think @ksperling was saying that if it started with a '@' it would be relative. So this one would go to edit state relative to current state, just like a relative url. So if we were in contact.list.details, this would take you to contact.list.details.edit. <a ui-state-ref="@edit">Edit</a>
<!-- I think I would prefer one of these more though -->
<a ui-state-ref=".edit">Edit</a>
<a ui-state-ref="/edit">Edit</a> And this one would go to absolute state called "edit" <a ui-state-ref="edit">Edit</a> |
Still leaves the parameters though, edited the examples... |
ah ok I get it now, the parameters...We could have the ui-state-ref string be interpolated so the state name could be dynamic. Then a seperate directive for parameters (kind of yuck). Would the parameters be interpolated too? Would think we could just do something like this: <a ui-state-ref="{{$scope.someStateName}}" ui-state-ref-params="{id: item.id, otherParam: item.otherValue}">Edit</a> Or maybe combine them, separated by a bar. <a ui-state-ref="{{$scope.someStateName}} | {id: item.id, otherParam: item.otherValue}">Edit</a> The truth is that people are most likely going to use URLs 95% of the time, so I think its ok that this is more verbose than that. Also, I'm not entirely sure what Igor is getting at. |
Keep in mind, if we're doing our own directive, we can do our own (simple) parser. We're not constrained by valid JavaScript. For example: <a ui-state-ref="@edit(id: item.id, otherParam: item.otherValue)">Edit</a> That should be pretty comprehensible and easy to parse. |
Yes, parameters definitely need to be supported. I was thinking these would be resolved based on the current state, i.e. any parameter that the target state has but that's not specified keeps it's value from the current state. I'm hoping this directive will be as easy to use as hard-coding an href, and it will have the advantage of being more DRY. If the directive is used consistently, you should be able to completely change the URL pattern of a state, and all links will change to match. A custom parser is an option, but would probably not be my first choice. I think it should work in a way that somebody familiar with Angular expressions can just use without having to think too much about. |
Can you provide some scenarios for the parameter "rollover" you just Michael
|
Obviously parameter values need to be able to be computed via expressions. I think it's probably OK if the target state name is just taken literally. |
@michaelwinser the best example is probably linking between states that share a parent state. In that case the parameters that belong to those shared ancestors should not need to be specified. In the current sample app for example, I'd like to be able to link from contact.details to contact.details.item without having to explicitly say In fact it may be a good idea to restrict this 'rollover' to only parameters of shared ancestors of the current and targeted states. |
I think we're thinking along the same lines. I think parent parameters Michael
|
Could it be just like: ui-href="@edit/{{itemId}}"
ui-href="admin.user.edit/{{itemId}}"
ui-action="@submit" // for forms to add fields values to params, but not in the url |
I think the directive should deal with the parameters as an object, rather then via string interpolation (which would then have to be parsed back into a structured representation). Can you elaborate on how/why you'd want to do "form submission" into state parameters? |
Then maybe $state.href as compliment to $state.go ng-href="{{$state.href('@edit', {id: item.id, otherParam: item.otherValue})}}"
ng-click="$state.go('@edit', {id: item.id, otherParam: item.otherValue})" Form submission flow very clear (or just familiar) with old-style server-side mvc :
In my js app I have wizard with states 'app.entry'(abstract) => 'app.entry.edit'(default) => ..(several steps) => 'app.entry.preview'(with submit button) => 'app.entry.submit' => 'app.thanks' |
I think we need to think of what is best (and easiest) for the user. I see the point about keeping parameters as an object, but it makes the syntax long and cumbersome. Maybe it's not worth it. Maybe let's use a syntax similar to search parameters... Actually that's ugly, but I'll leave it so we can at least see that this idea was suggested... Looking back at all the suggestions, I think the one that seems best to me is @ludinov's latest href and go suggestion. I don't love it though; wish there was something as elegant as the equivelent of this url: |
Yeah I think replicating web 1.0 MVC one-to-one in states would be a mistake -- I think it normally makes more sense for the controller thats associated with the form to handle the submit, and then (maybe) transition to another state. A state isn't the same as a controller, so I don't think you should have a separate state purely to "submit to" and then redirect somewhere else. Besides, entering a state should in general be side-effect free, or at least idempotent. We're not trying to do POST-redirect-GET here. Whatever would happen during POST in web 1.0 should be done by a controller, which then navigates to the correct state (what would have been the GET). I think wanting to submit a form directly into parameters of a new state is so much of a design smell that we maybe shouldn't support it explicitly -- you can always just have a controller method do that for you manually in about a line or two of code if it's really the right thing to do in a particular case. |
@ksperling - agree. thanks. |
@ludinov that actually looks pretty neat... maybe a bit of an abuse of filters though |
Personally I think @nateabele still has given the most simple and intuitive approach in: <a ui-state-ref="@edit(id: item.id, otherParam: item.otherValue)">Edit</a> Finding something inside angular that could direct us towards how this should be is sort of difficult... There is plenty of directives using multiple attributes though, so there wouldn't be anything in angular that wouldn't fit into the example from @timkindberg <a ui-state-ref="@state" ui-state-ref-params="{id: item.id, otherParam: item.otherValue}">Edit</a> Except that the consensus would properly be to just call the last attribute params... So: <a ui-state-ref="@state" params="{id: item.id, otherParam: item.otherValue}">Edit</a> Or even more crazy generic: <a ui-ref state="@state" params="{id: item.id, otherParam: item.otherValue}">Edit</a>
<ui-ref state="@state" params="{id: item.id, otherParam: item.otherValue}">Edit</ui-ref>
<ui-ref url="http://github.com">Edit</ui-ref>
<ui-ref url="/regular/:id" params="{id: item.id}">Edit</ui-ref> In the long run this might fit into the htmlAnchorDirective angular already has: https://github.com/angular/angular.js/blob/master/src/ng/directive/a.js |
For what it's worth, I think ludinov's suggestion is the most intuitive and least over the top magical. I like the idea that you could link to a state by name which has a URL associated with it. If you ever need to change URLs, all you have to change is the state definition. In my apps, I use a custom, global $router object that can handle building various routes for different resources such as $router.page(), $router.service(), $router.layout(), etc. which handles issue like base path adjustment (when developing in a subdirectory, etc.). If you link to a state, you don't have to worry about that problem from within layouts which is nice. The idea of using two attributes seems really clunky to me. |
Since we're chiming in on the syntax, I prefer Nate's approach. To my ui-state-href="@edit(param1, param2, ...)" I'm unsure about the @ prefix. What does it mean? Are values without the Michael On Tue, Feb 19, 2013 at 1:20 PM, Rob Schley notifications@github.comwrote:
|
The example of ngPluralize is interesting -- it's a structured syntax that contains (potentially) multiple angular expressions. Interesting (and somewhat clunky) that they need to be quoted though. Taking the ngPluralize approach, you'd end up with <a ui-state-ref="@edit(id: 'item.id')"> which is very counter-intuitive as it looks like you're assigning a literal to the parameter. It would look even more convoluted if you're actually assigning a literal: You'd need pretty deep integration with the $interpolate expression parser to do away with the need for having a delimiter around each parameter expression (otherwise it's difficult to know where an expression ends). At the minimum you'd need to reuse the tokenizer from $interpolate. Without having investigated if it would be feasible, this sounds like quite a bit of complexity, for merely cosmetic benefit. For me the added learning curve for the user of having to learn the custom syntax is a drawback as well. |
As per my comment on #19, combining a link with the highlight directive sounds like a common use-case that should be supported without having to repeat the state name and parameters. |
👍 |
I think a |
Is there any progress on this? |
I'm gonna call it, since we now have a working state URL / transition directive in master. We can continue to evolve it once I've finished implementing |
so what's the function for this ? |
Add a directive that understands the same short-hand syntax as issue #15 and can be used to generate hrefs.
The text was updated successfully, but these errors were encountered: