Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement a navigation bar in angularjs

Tags:

angularjs

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.

like image 473
Mark Avatar asked Aug 22 '13 22:08

Mark


1 Answers

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.

like image 156
Sergiu Paraschiv Avatar answered Nov 20 '22 10:11

Sergiu Paraschiv