如何实现在angularjs一个导航栏 [英] How to implement a navigation bar in angularjs

查看:174
本文介绍了如何实现在angularjs一个导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与angularjs为我创建了一个导航栏的新手开始。它有几个子菜单。但我不完全知道什么是对付使用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.

我要寻找一些例子或者一些例如code,可以在生产环境中使用。

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.

推荐答案

看一看 angular- UI / UI路由器。它增加了一个名为观点和各州您的应用程序。您可以定义的基础上,状态,在你的主模板区的程序是,显示了一定的模板+控制器。

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.

编辑:是的,$位置可以够一个简单的应用程序,但你一每屏控制器获取要你开始意识到你需要更多的东西100线$​​范围$表定义的时间

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.

这篇关于如何实现在angularjs一个导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆