在AngularJS,我可以使用当前路由在ngSwitch ngView外 [英] In AngularJS, can I use current route in ngSwitch outside of ngView
本文介绍了在AngularJS,我可以使用当前路由在ngSwitch ngView外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图改变页头取决于当前视图。标题是ngView之外。这是可能或者我需要把标题中的视图内?
我的code类似于此:
< DIV ID =头>
<格上=页面名称&GT NG-开关;
< DIV NG-开关时=家>!欢迎< / DIV>
< DIV NG-开关时=产品列表>产品< / DIV>
< DIV NG-开关时=联系>联系我们< / DIV>
< / DIV>
(很多不相关的code的放在这里)
< / DIV>< DIV ID =内容>
< DIV NG-视图>< / DIV>
< / DIV>
解决方案
给每个路由名称,当你定义它。再注入$路由到控制器中,然后让控制器发布到当前范围。然后,您可以在NG-开关绑定到$ route.current.name
I am trying to change the page header depending on current view. The header is outside of ngView. Is that possible or do I need to put the header inside the view?
My code looks similar to this:
<div id="header">
<div ng-switch on="pagename">
<div ng-switch-when="home">Welcome!</div>
<div ng-switch-when="product-list">Our products</div>
<div ng-switch-when="contact">Contact us</div>
</div>
(a lot of unrelated code goes here)
</div>
<div id="content>
<div ng-view></div>
</div>
解决方案
Give each route a name when you are defining it. Then inject $route into the controller, then have the controller publish it into the current scope. You can then bind the ng-switch to $route.current.name
这篇关于在AngularJS,我可以使用当前路由在ngSwitch ngView外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文