This repository was archived by the owner on Sep 8, 2020. It is now read-only.
This repository was archived by the owner on Sep 8, 2020. It is now read-only.
When would you getTasks() #12
Closed
Description
Given you hit the individual project state, which resolves a project to be injected into to the ProjectController.
Say you want to display the tasks for the project immediately for that state. At what point would you call the getTasks()? Would you do this right away in the ProjectController?
module.controller 'Project', ($scope, project) ->
$scope.project = project
$scope.project.getTasks()
Or, would you make it part of the resolve?
resolve:
project: (AppObject, $stateParams) ->
AppObject.getProject($stateParams.projectId).then (project) =>
project.getTasks().then() =>
project
Or maybe you were thinking something completely different?
The resolve works quite well with states, but once there aren't states I'm a little unsure on how to fetch the children.
Thanks for any help.
Activity
ProLoser commentedon Jul 31, 2014
One of the awesome parts about ui-router's resolve chaining is you can make them siblings:
Of course this will chain the queries and perhaps slow down the loading of the page. It just occurred to me that if ui-router doesn't load children states async then you can get a performance boost by placing the project's tasks into a substate, but this may not necessarily make sense for your navigation which is why the above solution should work too.
marcfallows commentedon Jul 31, 2014
Amazingly quick response. I didn't know ui-router would chain those resolves, very cool.
Substates is more what I had in mind, but I'm not sure how you would load the tasks into a substate of the project by default. The ui-router setup in that case isn't very clear to me so I'll need to dig into the docs a bit more.
ProLoser commentedon Jul 31, 2014
Yeah that SPECIFIC scenario has been sorta tricky for me in the past. Like lets say you get sent to
project
but really the default is alwaysproject.tasks
. What I've had to resort to doing is essentially putting a check to see if you were going to a specific substate already and if not, redirecting you toproject.tasks
in the controller ofproject
. It does cause theproject
state to finish loading and give the user more UI sooner, but it's been a bit annoying to code (you have to put a watcher on the routechange event and if someone goes fromproject.whatever
toproject
you push them back into tasks) but perhaps this is something worth requesting on ui-router.It's similar to the concept of an abstract state, like project essentially IS an abstract state, but if you DO navigate to it, you get pushed into a substate. In fact... angular-ui/ui-router#1235