-
Notifications
You must be signed in to change notification settings - Fork 3k
Dynamically modifying state views #379
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 do you mean by that comment? In my mind templates plug INTO views, its not a one or the other decision. |
I guess I find it weird that a single state can either specify one of |
How soon after? Does this necessarily have to happen at runtime, or would some deferred time still within config-time work?
I know. View targeting is pretty much the worst part of this library. Now that I've factored out
Yeah, under the API I'm working on, you'll be able to do something along the lines of
That's not entirely accurate. If you don't specify a |
I have such use cases, too. I'd love it if run time state definitions and redefintions (essentially last minute) were supported along with hierarcical definitions... my dream would be to retire angular-detour but in the short run my goal is to update it to match ui-router 0.2.0 :) My current use case requires fetching state definitions and components from outside the app. With detour and couch potato this is straightforward but upgrading it to 0.2.0 isn't going to be terribly enjoyable, even though it will be worth it -- @nateabele thank you very much for all of the work you put into it. Fwiw I think of a state as being a set of view specs each of which specifies a controller (optional) and a template. It doesnt much matter how many there are or what their names are. It seems quite similar to what @eahutchins is doing. You can achieve this pretty easily by laying your own service on top of ui-router. |
For the issue of having either a template or views, I think the solution that works today is a view with a name equal to empty string. If you always use this tecnique you can at least be consistent. |
Runtime, as the user is interacting with the app or external events are happening (like orientation change or window resize).
Great!
This is pretty much what I've started to attempt to implement... while you're at it could you add a
I understand, the problem I'm running into is that you always need a child state to fill in the views of a state, i.e. there's no way to have a current state with edit: I guess for this to work the |
Pretty sure you can have a state populate its own views. I've seen |
@timkindberg yeah actually with @nateabele's |
@eahutchins ok, but you also know that you should also be able to do it currently without needing a |
@timkindberg right, but not dynamically at runtime (which is the part I really need). |
@nateabele how are things going with the $view.load API? |
@eahutchins Heh, good timing. Just finished the second round of refactoring, and I'm testing it in my production app right now actually. |
Hi, i´m trying to port one old jsp application to angularjs. Our idea is a tab based application (like gmail). While a user is showing a list of items (List items tab), the user can click on one item to edit it, the application will open a new tab and render the edit form in this new tab (Item 1 tab). The user can click again over the "List item tab" and click to edit other item and then a new tab for edit this item is created. I have created a tabsService listening on stateChangeSuccess to open new tabs on state change, but i don´t know how to assign at runtime the correct tab. Each tab is created with a inner div and ui-view="statename". Is possible use the new $view service to implement this requirement?. |
@dagahe |
@eahutchins Sorry, I'm a space cadet. I just realized that the |
@eahutchins Based on my comment above, this issue should actually already be resolved. You can give it a try this way: $view.load("view.name@state", {
templateUrl: "/partials/foo.html",
controller: "MyController"
}); Let me know if you have any trouble with it, and we can reopen this. |
@nateabele thanks, I'll give it a try. |
@nateabele I think I've run into a problem: I can only load views which were mentioned at state definition time (in edit: I should clarify, I'd like to be able to have templates with named |
To clarify further: just like you can programmatically transition to states declared outside of your immediate context using names as dynamic bindings, you should be able to programmatically change UI configuration (views) at any time without knowing anything other than the name of the binding. The template should be the ground truth of what views are available to a state because that's really a declarative thing, not something you want to hard-code into potentially generic scripting at state declaration time. Named Example uses might be a |
do you have any sample code which proves this functionality, We wanted to do implement something similar. Any input is appreciated. Thanks |
We are facing a similar issue where we need to define the view names dynamically? @eahutchins : did you get any answer on this? |
I am sorry but no answer yet, this is one of the major issue we are facing with angular. We have to have show multiple views in same page dynamically. |
bump |
We finally ended up using ng-include and change it's template using $templateCache, something like shown below: HTML: Controller js code: // Call this function when you want to reload template with different url. Thanks |
Is #894 kind of what you might be looking for? |
Any updates on this? |
@nateabele, @timkindberg Hey, beginner ui-router user here. This might be a dumb question and I'm not really sure if it's been mentioned. Are we able to pass in state parameters to this function so that the view that's rendered reflects a different set of data? for example something like this... $view.load("view.name@state({num:10})", {
templateUrl: "/partials/foo.html",
controller: "MyController"
}); as opposed to $view.load("view.name@state", {
templateUrl: "/partials/foo.html",
controller: "MyController"
}); I was looking at the view.js file and I saw that it supports template parameters, but I'm not really sure if this is what I'm thinking of. Any input would be appreciated. |
@wchavezsalinas You can pass parameters, but not like that. See https://github.com/angular-ui/ui-router/blob/master/src/view.js#L31-L34 |
wondering if there was ever a clear answer on this? $view.load doesn't seem to do anything in v0.2.15. I tried it with fully qualified view names ('view.name@state'). I even tried updating to 1.0.0alpha0 and $view.load gives the error "viewConfig.hasTemplate() is not a function" I tried using All I'm trying to do is change the template property after the state has been defined ... for my use case it doesn't matter if it's in config or run, but run seems easier because we have the $state and $view services there. |
Changing a template string at runtime is best done with templateProvider |
Thank you. But is there any way to change the templateProvider function at runtime? I know I could refactor the code so the original templateProvider resolves a different template, however in this case it would be much simpler if I could simply change the templateProvider function. |
Hello @nateabele @christopherthielen I have similar situation. I want to chage the content of named view at runtime or similar. This is my question: |
I've got a use case for being able to alter the views associated with a state dynamically, after the state has already been defined. I also see some confusion between state and the views under a given state, it seems if you'd really like to use the views to allow reusable components (say a bunch of different types of graphs in a business dashboard app) you'd like to avoid having to define a new state for every possible permutation of view that the user might select. To clarify:
Imagine the user had the ability to select which types of views are being used for the table and graph, but that this selection was transient and not something the designer wanted to be able to navigate to. Currently this seems really hard to get working with ui-router, what I'd like is to be able to do something like:
$state.setViews({ 'viewname': { ... } })
This also brings up the issue of why states can only have templates or views, but not both. What was the thinking behind this restriction (or is it only an implementation limitation)? The use case I'm working on would benefit from being able to populate the current state's template with reusable components in named views (as well as those of any parent state). Am I missing some big drawback to being able to do this?
The text was updated successfully, but these errors were encountered: