您好,我正在使用 angular 8,我想在移动视图上切换 sidenav 组件。所以在移动媒体查询中,我使用这个 CSS 来隐藏 sidenav
@media screen and (max-width: 600px)
.sidenav {
visibility: hidden;
clear: both;
float: left;
margin: 10px auto 5px 20px;
width: 28%;
display: none;
}
所以在移动视图上,我在标题组件上有一个汉堡包图标。那么在单击时如何切换 sidenav 组件?
标题 HTML:-
<div class="header">
<fa-icon class="hamburger" [icon]="faBars"></fa-icon>
<div class="logo-section">
<img class="logo" [routerLink]="['/dashboard']" src="../../../assets/images/abc.png"/>
</div>
</div>
标题组件:-
@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.scss']
})
export class HeaderComponent implements OnInit {
searchText: string;
faBars = faBars;
constructor(private route: Router) { }
ngOnInit() {
}
}
Sidennav HTML :-
<div class="sidenav">
<div class="logo">
<!--
<img src="../../../assets/images/logo.png" alt="SKS" /> -->
</div>
<div class="sidenavbar">
<div class="menu" appMenuactive [routerLink]="['/dashboard']" [routerLinkActive]="['selected']">
<p class="menuicons">
<fa-icon [icon]="faTh"></fa-icon>
</p><span>
Dashboard
</span>
</div>
<div class="menu" appMenuactive [routerLink]="['/data']" [routerLinkActive]="['dataselect']">
<p class="menuicons">
<fa-icon [icon]="faTachometerAlt"></fa-icon>
</p><span>
Info
</span>
</div>
<div class="menu" appMenuactive [routerLink]="['/storage']" [routerLinkActive]="['dataselect']">
<p class="menuicons">
<fa-icon [icon]="faStar"></fa-icon>
</p><span>
Storage
</span>
</div>
</div>
</div>
Sidenav 组件:-
@Component({
selector: 'app-sidenav',
templateUrl: './sidenav.component.html',
styleUrls: ['./sidenav.component.scss']
})
export class SidenavComponent implements OnInit {
faTachometerAlt = faTachometerAlt;
faTh = faTh;
faStar = faStar;
constructor() { }
activatemenu = false;
ngOnInit() {
}
}
如何在移动视图中单击标题图标时使导航栏可见?