Sunday, 29 September 2013

Angular navigation: Show different sub navigation for different views

Angular navigation: Show different sub navigation for different views

I am still trying to wrap my head around how to approach things with
Angular and single page web apps on a conceptual level, so please bare
with me for this rather trivial seeming question.
On my app I have a menu that is consistent across pages/view, and a sub
menu that shows different links (to more nested child pages) for each main
page/view. I am unsure how to approach changing the sub menu. For now, I
have both the menu and sub menu in the body, as well as an ng-view
element.
First I thought I'll make a controller for the sub menu and loop over an
array of sub pages to display, updating the array as the main page/view
changes. This seems cumbersome and unintuitive, though, as I'd have to
keep a list of sub pages for each page in this separate controller, when
really, they are part of the main page's/view's logic, no? Then again,
I've read about the angular ui router and its implementation for nested
views - should I rather approach the sub menu as a nested view?
I know SO cries to see my actual code, but I am more struggling with how
to approach this problem, not with how to implement it. And it seems to me
that something like a sub menu changing per page/view must be a common
enough problem, that there is good recommendations for how to solve it.

No comments:

Post a Comment