I have the responsive mat-sidenav which generated with Angular Material 6. Open/close button for navigation panel work excellent, but then navigation panel is open pannel obscure part of the content.
How to make the content part like a rubber:
<!--CONTENT-->
<main>
<router-outlet></router-outlet>
</main>
I mean when the navigation bar is closed then the content width is 100% of the page. But when navigation bar is opened then content compressed to 85% (My navigation bar have width: 15%)
This is template:
<mat-sidenav-container class="sidenav-container">
<mat-sidenav
mode="side"
#drawer
class="sidenav"
[(opened)]="isOpened"
fixedInViewport="true"
[attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
[mode]="(isHandset$ | async) ? 'over' : 'side'"
[opened]="(isHandset$ | async)"
>
<mat-nav-list>
<span
*ngFor="let link of links"
routerLinkActive="active"
>
<a mat-list-item [routerLink]="[link.url]">
{{link.name}}
</a>
</span>
<span style="position: absolute; bottom: 1px; width: 100%">
<a mat-list-item class="waves-effect waves-orange" (click)="logout($event)">
Выйти
</a>
</span>
</mat-nav-list>
</mat-sidenav>
<mat-sidenav-content>
<mat-toolbar color="primary">
<button mat-icon-button (click)="drawer.toggle()">
<mat-icon>menu</mat-icon>
</button>
<span style="margin-left: 45%">Oasis Bot Manager</span>
</mat-toolbar>
</mat-sidenav-content>
</mat-sidenav-container>
<!--CONTENT-->
<main [ngStyle]="{'width': isOpened ? '85%' : '100%'}">
<router-outlet></router-outlet>
</main>
TypeScript side:
export class SiteLayoutComponent {
links = [
{url: '/vds_list', name: 'Статистика'},
{url: '/profile', name: 'Личный кабинет'}
];
isOpened;
isHandset$: Observable<boolean> = this.breakpointObserver.observe(Breakpoints.Handset)
.pipe(
map(result => result.matches)
);
constructor(private breakpointObserver: BreakpointObserver,
private auth: AuthService,
private router: Router) {
}
logout(event: Event) {
event.preventDefault();
this.auth.logout();
this.router.navigate(['/login']);
}
}
I'm trying bind width of content through [ngStyle] to [(opened)]="isOpened" state of mat-sidenav.
But not work. How to resolve this situation?
Your content area needs to be inside mat-sidenav-container below the toolbar:
<mat-sidenav-container class="sidenav-container">
<mat-sidenav
mode="side"
#drawer
class="sidenav"
[(opened)]="isOpened"
fixedInViewport="true"
[attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
[mode]="(isHandset$ | async) ? 'over' : 'side'"
[opened]="(isHandset$ | async)"
>
<mat-nav-list>
<span
*ngFor="let link of links"
routerLinkActive="active"
>
<a mat-list-item [routerLink]="[link.url]">
{{link.name}}
</a>
</span>
<span style="position: absolute; bottom: 1px; width: 100%">
<a mat-list-item class="waves-effect waves-orange" (click)="logout($event)">
Выйти
</a>
</span>
</mat-nav-list>
</mat-sidenav>
<mat-sidenav-content style="display:flex; flex-direction:column;">
<mat-toolbar color="primary">
<button mat-icon-button (click)="drawer.toggle()">
<mat-icon>menu</mat-icon>
</button>
<span style="margin-left: 45%">Oasis Bot Manager</span>
</mat-toolbar>
<!--CONTENT-->
<main>
<router-outlet></router-outlet>
</main>
</mat-sidenav-content>
</mat-sidenav-container>
Related
The Problem: In an angular project I have a single component for the sidenav menu and I'm trying to put other component sided with the sidenav, but since the sidenav element has full height the other component just goes to the bottom of the page. I tried to use display flex, but still goes to the bottom of the page.
Sidenav - html
<mat-drawer-container class="container" autosize>
<mat-drawer #drawer class="p-5" mode="side">
<!-- Content for side menu -->
<!-- Title -->
<h2 class="mt-5">Menu</h2>
<!-- Menu options-->
<button mat-button class="m-2" [matMenuTriggerFor]="workexperience">Experiência
Profissional</button>
<button mat-button class="m-2" [matMenuTriggerFor]="studies">Educação</button>
<button mat-button class="m-2" [matMenuTriggerFor]="skills">Habilidades</button>
<...>
<!-- Option work experience-->
<mat-menu #workexperience="matMenu">
<button mat-menu-item>text</button>
<button mat-menu-item>text</button>
</mat-menu>
<...>
</mat-drawer>
</mat-drawer-container>
<nav class="navbar navbar-light cyan darken-3 text-white fixed-top">
<button type="button" mat-button (click)="drawer.toggle()">
<mat-icon class="mx-2">menu</mat-icon>
<p class="mr-4 d-inline">Menu</p>
</button>
<button type="button" routerLink="/home" routerLinkActive="active" mat-raised-button>
<mat-icon class="d-inline mx-2" aria-label="Example home icon">home</mat-icon>
<p class="mr-4 d-inline">Home</p>
</button>
<a class="navbar-brand d-inline mx-5" routerLink="/bio">
<img class="rounded-circle z-depth-2" alt="80x80" height="35" src="https://mdbootstrap.com/img/Photos/Avatars/img%20(31).jpg"
data-holder-rendered="true">
<p class="d-inline mx-3 text-white">text</p>
</a>
</nav>
Sidenav- css
.container {
display: inline-block;
height: 100%;
background-color: white;
}
The other component that I want to be on the rigth of the navside.
The other component html
<mat-grid-list cols="4" rowHeight="500" class="m-5 sidenav-content">
<mat-grid-tile
*ngFor="let tile of tiles"
[colspan]="tile.cols"
[rowspan]="tile.rows"
[style.background]="tile.color">
{{tile.text}}
</mat-grid-tile>
</mat-grid-list>
The other component css
.sidenav-content{
display: flex;
height: 100%;
}
Hi i am Learning Angular
I just Made an angular Panel But I want It To Be Rtl But I do not Know How To do That
This Is My Panel
this Is My Html Code
<mat-toolbar color="primary">
<mat-toolbar-row>
<button mat-icon-button >
<mat-icon>menu</mat-icon>
</button>
<span> Admin Panel </span>
<div fxFlex fxLayout="row" fxLayoutAlign="flex-end">
<ul fxLayout="row" fxLayoutGap="20px">
<li>
<button mat-icon-button>
<mat-icon>settings</mat-icon>
</button>
</li>
<li>
<button mat-icon-button>
<mat-icon>help_outline</mat-icon>
</button>
</li>
</ul>
</div>
</mat-toolbar-row>
</mat-toolbar>
This Is My css
ul li{
list-style: none;
}
Do you mean something like that?
Code:
<mat-toolbar color="primary">
<mat-toolbar-row fxLayout="row-reverse">
<button mat-icon-button (click)="sidenav.toggle()">
<mat-icon>menu</mat-icon>
</button>
<span> Admin Panel </span>
<span fxFlex="1 1"></span>
<button mat-icon-button>
<mat-icon>settings</mat-icon>
</button>
<button mat-icon-button>
<mat-icon>help_outline</mat-icon>
</button>
</mat-toolbar-row>
</mat-toolbar>
<mat-sidenav-container>
<mat-sidenav #sidenav position="end">
Sidenav content
</mat-sidenav>
<mat-sidenav-content>
Sidenav content
</mat-sidenav-content>
</mat-sidenav-container>
Using the fxLayout="row-reverse"-property in your <mat-toolbar-row>
Here is a stackblitz: https://stackblitz.com/angular/kgnvebakmpj
fyi if you only have one toolbar row, you can leave out the <mat-toolbar-row>.
I know this has been asked, but none of the solutions work.
I have following html and I can get the image displayed if I use the commented img-element
<img src="assets/utgmap.jpg">
and comment away the following div-element. However I would like to have background image for the div instead and it's not working. CSS definition is in the end of the file and there's no 404 error for the image so it can be fetched but is is not displayed.
HTML:
<mat-sidenav-container class="sidenav-container">
<mat-sidenav #drawer class="sidenav" fixedInViewport="true"
[attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
[mode]="(isHandset$ | async) ? 'over' : 'side'"
[opened]="!(isHandset$ | async)">
<mat-toolbar>Menu</mat-toolbar>
<mat-nav-list>
<a mat-list-item href="#">Link 1</a>
<a mat-list-item href="#">Link 2</a>
<a mat-list-item href="#">Link 3</a>
</mat-nav-list>
</mat-sidenav>
<mat-sidenav-content>
<mat-toolbar color="primary">
<mat-toolbar-row>
<button mat-icon-button (click)="toggleSidenav.emit()">
<mat-icon>menu</mat-icon>
</button>
<span>webgisproto</span>
<button mat-icon-button>
<mat-icon>settings</mat-icon>
</button>
<button mat-icon-button>
<mat-icon>help_outline</mat-icon>
</button>
<button mat-icon-button [matMenuTriggerFor]="menu">
<mat-icon>exit_to_app</mat-icon>
</button>
<mat-menu #menu="matMenu">
<button mat-menu-item (click)="logout()">
<mat-icon>exit_to_app</mat-icon>
<span>Sign out</span>
</button>
</mat-menu>
</mat-toolbar-row>
</mat-toolbar>
<app-menu></app-menu>
<!-- THIS WORKS!!
<img src="assets/utgmap.jpg">
IF I UNCOMMENT THIS AND COMMENT OUT THE FOLLOWING DIV -->
<div class="bgimg">
<div class="testclass">
<mat-list color="primary">
<mat-list-item>
<button mat-icon-button>
<mat-icon>settings</mat-icon>
</button>
</mat-list-item>
<mat-list-item>
<button mat-icon-button>
<mat-icon>help_outline</mat-icon>
</button>
</mat-list-item>
</mat-list>
</div>
</div>
</mat-sidenav-content>
CSS:
.testclass {
float: right;
}
.bgimg {
background: url('../../assets/utgmap.jpg') no-repeat center center fixed;
}
If I change the path above there will be error.
You need to set a dimension to your div. The following code will display the image in full screen.
html, body {
height: 100%;
}
.bgimg {
display:block;
width:100%;
height:100%;
background: url('../../assets/utgmap.jpg') no-repeat center center fixed;
}
I'm using angular 5 and angular material. i have a mat-sidenav-container that consists of mat-sidenav and a mat-sidenav-content. and I have a mat-toolbar in the top of my page. I want to use routerLink in my sidenav-content but it's not working however it works in my mat-toolbar. even a button click function is not working. here are my codes below
<mat-toolbar>
<mat-toolbar-row>
<div>
<button mat-icon-button class="button" (click)="sidemenu.toggle()">
<mat-icon class="menu">menu</mat-icon>
</button>
</div>
<div mat-card-avatar class="example-header-image"></div>
</mat-toolbar-row>
</mat-toolbar>
<mat-sidenav-container class="example-container">
<mat-sidenav mode="side" opened #sidemenu>
<mat-nav-list>
<mat-list-item appAccordionLink>
<a appAccordionToggle>
<mat-icon class="list-icon">inbox</mat-icon>
<span class="link">IncomingMail</span>
<span fxFlex></span>
</a>
</mat-list-item>
</mat-nav-list>
</mat-sidenav>
<mat-sidenav-content>
<a routerLink="/">Home</a>
</mat-sidenav-content>
<router-outlet></router-outlet>
</mat-sidenav-container>
I have a mat-sidenav in my project and I want to link a text to another URL, but when I use routerLink it doesn't work but it works out of the side-nav.it even works in the toolbar. what is the problem? here are my codes:
HTML:
<mat-toolbar>
<mat-toolbar-row>
<div>
<button mat-icon-button class="button" (click)="sidemenu.toggle()">
<mat-icon class="menu">menu</mat-icon>
</button>
</div>
<div mat-card-avatar class="example-header-image"></div>
</mat-toolbar-row>
</mat-toolbar>
<mat-sidenav-container>
<mat-sidenav mode="side" opened #sidemenu>
</mat-sidenav>
<mat-sidenav-content>
<div routerLink="/">home</div>
</mat-sidenav-content>
<router-outlet></router-outlet>
</mat-sidenav-container>