Search code examples
angularbreakpointsangular8angular-flex-layout

How to setup Angular Flex Layout breakpoints with Angular 8


does anybody know how to setup Flex Layout breakpoints using Angular 8 and Angular Flex Layout. I'm trying to use them within the template like this:

    <div fxFlex="100%" fxFlex.md="20%" fxFlex.gt-md="50%">
        My Content
    </div>

This is not working currently. Some of my settings:

  • Array of breakpoints in constants.ts file:
        import { BREAKPOINTS } from '@angular/flex-layout';

        export const OVERRIDE_BREAKPOINTS = [
            {
                alias: 'xs',
                mediaQuery: 'screen and (min-width: 1px) and (max-width: 599px)',
                overlapping: false
            },
            ...
        ]

         export const BreakPointsProvider = {
             provide: BREAKPOINTS,
             useValue: OVERRIDE_BREAKPOINTS,
             multi: true
         };
  • Settings in app.module.ts:
        imports: [
            FlexLayoutModule.withConfig({}, OVERRIDE_BREAKPOINTS),
            ...
        ]


        providers: [
            BreakPointsProvider
            ...
        ]

I don't know what else should I add to make it work.

Thanks in advance!


Solution

  • I ended up using a previous version of Angular with the latest version of Angular Flex Layout, this is working as expected:

    package.json:

    {
      "name": "angular-app",
      "version": "0.0.0",
      "scripts": {
        "ng": "ng",
        "start": "ng serve",
        "build": "ng build",
        "test": "ng test",
        "lint": "ng lint",
        "e2e": "ng e2e"
      },
      "private": true,
      "dependencies": {
        "@angular/animations": "^8.0.0",
        "@angular/cdk": "8.0.2",
        "@angular/common": "8.0.0",
        "@angular/compiler": "8.0.0",
        "@angular/core": "8.0.0",
        "@angular/flex-layout": "8.0.0-beta.26",
        "@angular/forms": "8.0.0",
        "@angular/material": "^8.0.2",
        "@angular/platform-browser-dynamic": "8.0.0",
        "@angular/platform-browser": "8.0.0",
        "@angular/router": "8.0.0",
        "@auth0/angular-jwt": "^3.0.0",
        "@types/jasmine": "2.8.16",
        "@types/jasminewd2": "2.0.8",
        "@types/node": "8.9.5",
        "core-js": "2.6.9",
        "hammerjs": "^2.0.8",
        "rxjs": "6.5.2",
        "zone.js": "0.9.1"
      },
      "devDependencies": {
        "@angular-devkit/build-angular": "~0.10.0",
        "@angular/cli": "~7.0.2",
        "@angular/compiler-cli": "~7.0.0",
        "@angular/language-service": "~7.0.0",
        "@types/jasmine": "~2.8.8",
        "@types/jasminewd2": "~2.0.3",
        "@types/node": "~8.9.4",
        "codelyzer": "~4.5.0",
        "jasmine-core": "~2.99.1",
        "jasmine-spec-reporter": "~4.2.1",
        "karma": "~3.0.0",
        "karma-chrome-launcher": "~2.2.0",
        "karma-coverage-istanbul-reporter": "~2.0.1",
        "karma-jasmine": "~1.1.2",
        "karma-jasmine-html-reporter": "^0.2.2",
        "karma-spec-reporter": "0.0.32",
        "protractor": "~5.4.0",
        "ts-node": "~7.0.0",
        "tslint": "~5.11.0",
        "typescript": "~3.1.1"
      }
    }
    

    app.module.ts:

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    
    import { AppRoutingModule } from './app-routing.module';
    import { AppComponent } from './app.component';
    import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    
    import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
    import { ReactiveFormsModule, FormsModule } from '@angular/forms';
    
    import { FlexLayoutModule } from '@angular/flex-layout';
    import { AuthInterceptor } from './auth/auth-interceptor';
    
    @NgModule({
      declarations: [ ],
      imports: [
        AppMaterialModule,
        AppRoutingModule,
        BrowserAnimationsModule,
        BrowserModule,
        FlexLayoutModule,
        FormsModule,
        HttpClientModule,
        ReactiveFormsModule,
        SnackBarModule
      ],
      providers: [
        { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true }
      ],
      bootstrap: [AppComponent],
      entryComponents: [ ]
    })
    export class AppModule { }
    

    I hope it helps someone.