Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How set up Angular Material Footer via Flex-Layout

How set up the footer in my app (I use Angular Material) so that it:

  1. sticks to the bottom if the content height is less than view-port
  2. moves down / gets pushed down if the content height is more than view-port

One more important thing - I would like to achieve this via angular/flex-layout, not via the standard HTML/CSS 'flex-box'.

<mat-sidenav-container>
  <mat-sidenav #sidenav
    fixedInViewport="true"
    [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
    [mode]="(isHandset$ | async) ? 'over' : 'side'"
    [opened]="!(isHandset$ | async)">

    <mat-nav-list>
      <mat-list-item *ngFor="let li of listItems" routerLink="{{li.link}}">
        <mat-icon mat-list-icon>{{li.icon}}</mat-icon>
        <p mat-line>{{li.name}}</p>
      </mat-list-item>
    </mat-nav-list>
  </mat-sidenav>
  <mat-sidenav-content>

    <app-header (menuButtonClick)="sidenav.toggle()"></app-header>

    <ng-content select="[outlet]"></ng-content>

    <app-footer></app-footer>

  </mat-sidenav-content>
</mat-sidenav-container>   

Thank you all.

like image 791
PaxForce Avatar asked Dec 21 '18 15:12

PaxForce


People also ask

How do I import Flex layout into angular materials?

From your project folder, run the following command to install Flex Layout: npm install @angular/flex-layout @10.0. 0-beta. 32.

How do I use angular Flex layout?

Installation of Angular Flex-LayoutUse the following command to use Angular Flex layouts in your projects. After installing flex layout we need to import flexLayoutModule in our app. module. ts file as shown below.

Does angular material use Flexbox?

Overview. Angular Material's Layout features provide sugar to enable developers to more easily create modern, responsive layouts on top of CSS3 flexbox. The layout API consists of a set of Angular directives that can be applied to any of your application's HTML content.

Is angular Flex layout deprecated?

2.0.This has been deprecated and removed.


2 Answers

Here is a solution in few lines if you prefer to fill your content instead of your footer (Akhi's solution):

app.component.html:

<div fxLayout="column" fxFlexFill>
    <app-header></app-header> // your header
    <div fxFlex>
        <router-outlet></router-outlet> // your content
    </div>
    <app-footer></app-footer> // your footer
</div>

styles.css:

html, body {
    height: 100%;
    box-sizing: border-box;
    margin: 0;
}
like image 169
Emerica Avatar answered Oct 17 '22 01:10

Emerica


Make the container flex and direction column by adding fxLayout="column" and make the footer sticky bottom by fxFlexOffset="auto"

  <mat-sidenav-content fxLayout="column">

    <app-header (menuButtonClick)="sidenav.toggle()"></app-header>

    <ng-content select="[outlet]"></ng-content>

    <app-footer fxFlexOffset="auto"></app-footer>

  </mat-sidenav-content>
like image 10
Akhi Akl Avatar answered Oct 17 '22 03:10

Akhi Akl