, , , , , .
:
, ng2-bootstrap current collapse display: none display: block, . ( , ).
, - , . ng2-bootstrap , Angular 2+ , - , ( , ). , .
:
, , , , DRY . , , , , :
- ng2-bootstrap , , .
[collapse]=isCollapsed() ( ). - , .
- , (), .
- # 2 # 3.
:
animations.ts
import { trigger, state, transition, animate, style } from '@angular/core';
export class Animations {
public static slideInOut = trigger('slideInOut', [
state('true', style({ height: '0px' })),
state('false', style({ height: '*' })),
transition('1 => 0', animate('500ms ease-in')),
transition('0 => 1', animate('500ms ease-out'))
]);
}
app.component.ts
import { Component, trigger, state, style, transition, animate } from '@angular/core';
import { Animations } from './animations';
@Component({
selector: 'my-app',
templateUrl: './app/app.component.html',
styleUrls: ['./app/app.component.css'],
animations: [ Animations.slideInOut ]
})
export class AppComponent {
private collapsed: boolean;
constructor() {
this.collapsed = true;
}
public isCollapsed(): boolean {
return this.collapsed;
}
public setCollapsed(): void {
this.collapsed = true;
}
public toggleMenu(): void {
this.collapsed = !this.collapsed;
}
}
app.component.html
<header>
<nav class="navbar navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" (click)="toggleMenu()">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
</div>
</nav>
<nav role="navigation" class="navbar-fixed-top-responsive">
<div class="vertical-menu" [@slideInOut]="isCollapsed()">
<ul class="menu-item">
<li><a>menu1</a></li>
<li><a>menu2</a></li>
<li><a>menu3</a></li>
</ul>
</div>
</nav>
</header>