I load a list of recipes before I want to load my page. I need this list in any child state. Depending on the $stateParam
I want to pre-filter this list.
Questions
- Can I access the
$stateParam
in any way from the parent state? - Is it a better design to use a service and load the data in the child state and pass it via the service (where are disadvantages)?
I avoided the second solution because the resolve allowed me to switch between the child states without reloading the data (or without checking if the data has been loaded yet).
Research I'm aware that a parent state does not know anything what happens in the child state. But the child state knows of variables in the parent state. I guess this is what this solution used: angular ui-router and accessing child state params from parent
But I didn't get it working and also I don't want to have a url for the parent state because it is never loaded solo.
Code
.state "widget",
templateUrl: "app/widget/widget.html"
controller: "WidgetCtrl"
resolve:
Recipes: ($http, $stateParams) ->
console.log "$stateParams.oldContext #{$stateParams.oldContext}"
return $http.get('/getProovenRecipes').then( (result) ->
#console.log result.data
return result.data
)
.state "widget.recipes",
views:
'recipes':
templateUrl: "app/widget/recipes/recipes.html"
controller: "RecipesCtrl"
controllerAs: "recipesController"
.state "widget.recipes.tags",
url: "/widget/{context}"
views:
'tags@widget':
templateUrl: "app/widget/tags/tags.html"
controller: "TagCtrl"
controllerAs: "tagController"