How set up Angular Material Footer via Flex-Layout

PaxForce picture PaxForce · Dec 21, 2018 · Viewed 23.1k times · Source

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.

Answer

Emerica picture Emerica · Jun 2, 2019

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;
}