January 2017 Update :
Team
Angular 2 recently added the new NPM flex-layout package for layout only. This is a standalone package independent of angular material.
Full instructions are available on the github README page.
Install the module:
npm install @ angular / flex-layout -save
In app.module.ts (or equivalent) declare a module:
import {FlexLayoutModule} from "@angular/flex-layout"; @NgModule({ imports: [ ... FlexLayoutModule ], ... })
Layout Example:
<div class="flex-container" fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center center" fxLayoutAlign.xs="start"> <div class="flex-item" fxFlex="20%" fxFlex.xs="40%"> </div> <div class="flex-item" fxFlex> </div> <div class="flex-item" fxFlex="25px"> </div> </div>
Here is a plunker example taken from the github flex-layout page.
Original answer :
The docs you refer to refer to the material of the corner1. Angular2 stuff still does not have layout directives.
You can easily create a directive yourself in a simple way.
All you need to know:
layout="row" matches style="display:flex;flex-direction:row"
layout="column" => style="display:flex;flex-direction:column"
And flex equals style="flex:1"
As directives:
@Directive({ selector:'[layout]' }) export class LayoutDirective{ @Input() layout:string; @HostBinding('style.display') display = 'flex'; @HostBinding('style.flex-direction') get direction(){ return (this.layout === 'column') ? 'column':'row'; } }
The flex directive, use it as: <div flex> or <div flex="10"> any number from 0 to 100%. In addition, just for fun, I added a reduction and increase in inputs
@Directive({ selector:'[flex]' }) export class FlexDirective{ @Input() shrink:number = 1; @Input() grow:number = 1; @Input() flex:string; @HostBinding('style.flex') get style(){ return `${this.grow} ${this.shrink} ${this.flex === '' ? '0':this.flex}%`; } }
To use them everywhere without adding them to each component:
@NgModule({ imports: [ BrowserModule ], declarations: [ AppComponent,FlexDirective ,LayoutDirective ], bootstrap: [ AppComponent ] }) export class AppModule { }
Here is an example in plunk