如何使用 Angular 8 设置 Angular Flex Layout 断点

How to setup Angular Flex Layout breakpoints with Angular 8

有谁知道如何使用 Angular 8 和 Angular Flex Layout 设置 Flex Layout 断点。我正在尝试像这样在模板中使用它们:

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

这目前不起作用。我的一些设置:

        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
         };
        imports: [
            FlexLayoutModule.withConfig({}, OVERRIDE_BREAKPOINTS),
            ...
        ]


        providers: [
            BreakPointsProvider
            ...
        ]

我不知道我还应该添加什么才能让它发挥作用。

提前致谢!

您需要像这样更新您的 HTML:

<div class="container"
     fxLayout
     fxLayout.xs="column"
     fxLayoutAlign="center"
     fxLayoutGap="10px"
     fxLayoutGap.xs="0">
  <div class="item item-1" fxFlex="15%">Item 1</div>
</div>

for more information click here

我最终使用了以前版本的 Angular 和最新版本的 Angular Flex Layout,这按预期工作:

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

希望对大家有所帮助。