README.md
June 17, 2026 ยท View on GitHub
ng-flex-layout
Support my open-source code as a sponsor
- Updated to Angular 21.2.9
- Migrated from tslint to eslint
- Migrated tests to Vitest
- Added non-breaking Signals wrappers (RxJS remains the base API)
Angular Flex Layout provides a sophisticated layout API using Flexbox CSS + mediaQuery. This module provides Angular developers with component layout features using a custom Layout API, mediaQuery observables, and injected DOM flexbox-2016 CSS stylings.
The Flex Layout engine intelligently automates the process of applying appropriate Flexbox CSS to browser view hierarchies. This automation also addresses many of the complexities and workarounds encountered with the traditional, manual, CSS-only application of box CSS.
The real power of Flex Layout, however, is its responsive engine. The Responsive API enables developers to easily specify different layouts, sizing, visibilities for different viewport sizes and display devices.
Getting Started
Start by installing the Angular Layout library and CDK from npm:
npm install -s ng-flex-layout @angular/cdk
Next, import the Layout module in your app's module.
app.module.ts
import { NgModule } from '@angular/core';
import { FlexLayoutModule } from 'ng-flex-layout';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [FlexLayoutModule],
bootstrap: [AppComponent]
})
export class AppModule { }
After configuration, use the Angular Layout attributes in your HTML tags:
<div fxLayout="row" fxLayoutAlign="space-between">
<div>Item 1</div>
<div>Item 2</div>
</div>
Check out all of the available options for using Angular Layout in your application.
Signals (Optional)
RxJS remains the canonical API; Signals wrappers are provided as conveniences for Signal-based components.
MediaObserver.asSignal()(wrapsasObservable()viatoSignal())MatchMedia.observeAsSignal()(wrapsobserve()viatoSignal())MediaMarshaller.trackValueAsSignal()(wrapstrackValue()viatoSignal())
๐ ๏ธ Troubleshooting / FAQ
Error: NG0304: 'fxLayout' is not a known property of 'div'
- Solution: Ensure that
FlexLayoutModuleis imported in your module or standalone component.
Error: Cannot find module '@angular/cdk'
- Solution:
ng-flex-layoutrelies on the Angular CDK. Ensure you have installed@angular/cdkmatching your Angular version.
npm install @angular/cdk@^21
Error: Vitest: Failed to resolve import "..."
- Solution: When running
npm run test, ensurevite-tsconfig-pathsis correctly resolving paths in yourvitest.config.ts. Runnpm run buildonce to generate necessary dist files if path mapping fails.
Quick Links
Demos
Developers
Browser Support
License
The sources for this package are in this repository: https://github.com/alessiobianchini/ng-flex-layout
License: MIT