【发布时间】:2017-05-10 01:52:44
【问题描述】:
我有一个侧边栏,您可以在点击外部或点击里面的 X 时关闭它。但是我需要在更改路线时自动关闭(例如从主页到关于或联系人保持打开状态,但我需要它折叠)
<md-toolbar class='toolbar' color="primary" >
<button md-icon-button (click)="nav.open()">
<md-icon class="md-24">menu</md-icon>
</button>
</md-toolbar>
<md-sidenav-container>
<md-sidenav #nav>
<md-nav-list>
<button md-icon-button (click)="nav.close()">
<md-icon class="md-24">close</md-icon>
</button>
<a md-list-item routerLink='home'class="active"> Home </a>
<a md-list-item routerLink='about' class= "page-scroll" > About us</a>
<a md-list-item routerLink='discount' class= "page-scroll" >Discounts </a>
<a md-list-item routerLink='contact'class= "page-scroll" >Contact </a>
<a md-list-item routerLink='order' class= "page-scroll" >Order</a>...
.md-toolbar {
padding-top: 1em;
align-self: flex-start;
height:5em;
}
.toolbar{
position: fixed;
top: 0;
left: 0;
z-index: 9999;
width: 100%;
height: 50px;
}
md-nav-list{
margin-left: 20px;
margin-right: 10px;
margin-top: 80px;
font-size: 1.2em;
font-family: Raleway;
}
@media screen and (max-width: 600px) {
.logo {
display: none }
.search{
}
}
html {
height: 100%;
}
body {
min-height: 100%;
display: flex;
flex-direction: column;
}
.container{
margin-top: 100px;
margin-bottom: 100px;
flex: 1 0 auto;
}
When I choose another tab the background is still black and sidebar is opened, don't collapse
我发现一些看起来像是我需要的东西,但它是为 AngularJs 准备的。 pkozlowski.opensource 如何将它用于 Angular 2
如果您希望在路由成功更改时关闭所有打开的模式,您可以在一个中心位置通过监听 >$routeChangeSuccess 事件来执行此操作,例如在应用程序的运行块中:
var myApp = angular.module('app', []).run(function($rootScope, $uibModalStack) {
$uibModalStack.dismissAll();
});
【问题讨论】:
标签: navigation angular2-routing sidebar auto-close