Skip to content

Adaptive Layouts

Thomas Burleson edited this page Feb 28, 2017 · 12 revisions

Several Angular Material 1 applications: Material-Adaptive have been implemented using custom Flexbox CSS. These efforts illustrated the needs and features within a responsive, adaptive application.

screen shot 2016-11-05 at 7 26 56 am

Different from responsive layouts where components change sizes and positions, the concepts of Adaptive layouts provide for UX where different components may be used for different breakpoints.

Animations can also be extended to support MediaQuery activations: different animations will run for different viewport sizes.

Developers can use the following directives to achieve some Adaptive UX goals:

  • fxHide
  • fxShow
  • ngIf

For examples of fx-hide usages in Adaptive layouts, please review the demo Show & Hide Directives:


Core Directives + Responsive Features

Responsive features for core Angular directives:

  • [ngStyle.<alias>]=""
  • [ngClass.<alias>]=""
  • *ngIf.<breakpoint alias>="" is not yet supported.

Here is the current solution solution to enabled responsive/adaptive features with *ngIf:

import {ObservableMedia} from '@angular/flex-layout';

@Component({
  selector : 'my-mobile-component',
  template : `
      <div *ngIf="media.isActive('xs')">
         This content is only shown on Mobile devices
      </div>
      <footer>
         Current state: {{ }}
      </footer>
  `
})
export class MyMobileComponent {
  public state = '';
  constructor(public media:ObservableMedia ) {
    media.asObservable()
      .subscribe((change:MediaChange) => {
        this.state = change ? `'${change.mqAlias}' = (${change.mediaQuery})` : ""
      });
  }
}
Clone this wiki locally