11

Starting with angularjs as a newbie I have created a navigation bar. It has several sub menus. But I am not completely sure what is the best practice to deal with it using angularjs. I would like to keep track of the current selected menu item to make it 'active' and change the rendered template depending on the selection.

I am looking for some examples or some example code, that can be used in production environment.

Sorry for this very generic question, but I hope someone can help me.

2
  • 1
    Use the $location service to change the current route, and know which route is currently displayed. Commented Aug 22, 2013 at 22:23
  • 1
    See stackoverflow.com/questions/16199418/… Commented Aug 23, 2013 at 13:28

1 Answer 1

5

Have a look at angular-ui/ui-router. It adds named views and states to your app. You can define "areas" in your main template that, based on the "state" your app is in, display a certain template+controller.

Edit: yes, $location could be enough for a simple application but by the time your one-per-screen controller gets to be 100 lines of $scope.$watch definitions you start realizing you need something more.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that was the example I was looking for. I will have a closer look at it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.