-
Notifications
You must be signed in to change notification settings - Fork 3k
two active states under one url #339
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
What are you hoping to achieve by doing that? How are you expecting it |
I'm trying to achieve exactly what I described.. Let's say Err.. is it any clearer? |
Well its a bit confusing still what you are trying to avoid.
This part makes sense. I think your code above is valid, you'd have to try it out to confirm though. Basically,
It's your use of the word "components" that makes this unclear. That word has so many meanings in ui-router world. Are you talking about templates? Also do you realize that by splitting the "components" out into two different states, that only one will be visible at a time? Whereas if they were in the same state, you could potentially see both on screen simultaneously? These are the questions that cause me to be confused. |
Component as in some sort of element.. let's say Now what would happen after clicking on one of the arrows, if I had both carousels in one state with Better a little? |
Yes better, because now I understand generally what it is you want to achieve. Could you flesh the code out a bit more? Where would you plug the templates in? What would the templates look like? Sorry I can't give you a definitive answer yet, its still to early to tell if its going to achieve the result you are looking for. My gut is saying that that code is not going to do what you want it to. |
Well I'm somewhat sure the code, as I posted it, wouldn't work. Ideally it should be like this state('carousels', {
abstract: true,
template: '<h1>Cats and dogs</h1>'
+ '<div ui-view></div>' // this would/should be for cats
+ '<div ui-view></div>' // this would/should be for dogs
})
.state('carousels.cats', {
url: '/carousels?catPage'
template: '<a href="" ng-click="setStateParamCatPageToPlusOne">next set of cats</a><img ng-repeat="cat in catsOnThisPage" />'
})
.state('carousels.dogs', {
url: '/carousels?dogPage'
template: '<a href="" ng-click="setStateParamDogPageToPlusOne">next set of dogs</a><img ng-repeat="cat in dogsOnThisPage" />'
})
But afaik you can't have two ui-view on the same "level", and that's the whole problem.. |
@fxck You are able to have several views on a single state, you need to use named views and the views property in this case. https://github.com/angular-ui/ui-router/wiki/Multiple-Named-Views But it really sounds more like you should use a single view and make one or more custom directives instead. |
@jeme named views wouldn't work in this case, since you can't give a named view an url param(or can you?). Directive would work indeed, it would be pretty simple if I didn't want those params visible in the url. But I do.. |
There is a ton of ways you can make a directive be based on url parameters. One would be to access the location service in the directive and pull parameters from there, this is rather direct and might not be the most wanted way. But depends on the implementation still. Another is to use data-binding and instruct a directive to "watch" for changes on that parameter, then through a controller grap those parameters from either $location or some other relevant source. So... In other words... you could still easily use directives... The thing is, using "views" for components is not really what they are meant for, and it makes your application much more complex than what it has to be, a directive is declarative and easy to use... Granted there is a learning curve for you to implement them, but I would not recommend using views for components, they are for larger aspects of the application. |
Well that's new for me, looking at this https://github.com/angular-ui/ui-router/wiki/Multiple-Named-Views each of those(graph, table, filter), looks like a component to me. Either way, thanks for the information, I didn't quite realize you could use $location. |
Yeah ok, @jeme is right. What you are trying to do may not be possible without a decent amount of custom work and a very good understanding of how ui-router works behind the scenes. What you want isn't included out-of-the-box. There is some talk about not refreshing the whole view when parameters change in the future (or an option for it) but its not in there yet. |
It's just an advice... I would use ui-router for the bigger parts and groupings of your application where there are more clear cuts, but date-time selectors, carousels, accordions, tab-views and so on are more what Directives do well... A While back we tried to think in the same lanes for tab views, but it's just not "smart"... it becomes strange and hard to understand, and not even possible where you don't wan't them to reload each other. So, what I would do was to let UI-Router load a single view, defining both carousels just on the url You may be able to get UI-Router still do some of the work for you by defining "empty" sub-states. But I think it would be just as easy to either use the $location service or bind to it's parameters as it sounds to me like you wan't the parameters to be more independent of each other making the following:
Valid? One way would be to add a controller to the view to do something like: angular.module('carouselapp').controller('carouselsController', ['$location', '$scope', function(loc, sc) {
$scope.$on('$locationChangeSuccess', function() {
$scope.currentCat = $location.search().cat;
$scope.currentDog = $location.search().dog;
});
}]); Then the view would be something like: <carousel id="catCarousel" current="currentCat" data="cats" />
<carousel id="dogCarousel" current="currentDog" data="cats" /> It is unfortunately needed to jump to the location service as UI-Router doesn't have the same concept as the original router of sending an "update" out when search parameters changed... (Not As far as I know at least) |
Just a side note, I used carousel because I thought it would be easy to imagine, but in my actually case the first "component" is a graph of the current week, with possibility to move to previous/next week etc, each day also serves as a tab, second "component" is a huge ass table of entries for the selected day.. |
This sounds like the "components as independent state machines" feature that was discussed previously. Essentially there's a high level of complexity in this because (1) the global state machine will effectively contain "orthogonal regions" that can be active at the same time (2) mapping of URLs to states and back also becomes much more complex as in this model any node in the state tree that represents an orthogonal region has to ask each sub-region for a URL and somehow munge this into one URL, and undo the process on the way back in. |
I think this is out-of-scope for the project in its current incarnation. |
Well I don't think this would be a feasible feature in any future versions either, it seems to complex to create something generic around it, also I am afraid that it would allow people to generate something that gives horrors. What I think UI-Router could do was to allow for a similar feature as we saw under the Router, where you had RouteUpdate to allow the developer to hook into parameter updates that was sort of "optional" (in the original router that was search parameters only AFAIK). But that would allow you to trap that event in a parent controller and update scope fields and as an effect have directives like tab-views and so on bound to that... sort of like outlined above, but we could provide a much cleaner hook for it... E.g. something like |
Does anyone have an example of using a directive that would respond just to hash changes/html5 state events, so that we could implement having two active states in the url? |
It's basically what @jeme posted $scope.$on('$locationChangeSuccess', function() {
$scope.currentCat = $location.search().cat;
$scope.currentDog = $location.search().dog;
}); $location.search() contains an object with all the state params |
ah whoops, yes, I see now, thank you! |
Is this possible?
I could put both in the same state and use
views
, but then a change in parameter onroot.one
would also re-renderroot.two
#84 #160 are probably somewhat related issue..
The text was updated successfully, but these errors were encountered: