Angular 5 Mat-grid list responsive

后端 未结 6 1695
灰色年华
灰色年华 2021-01-30 03:08

i created grid list with column 6 and i want to be grid title take 100% width on small screen devices. Now it creates 6 column on small screens as well

Expected: One gri

6条回答
  •  滥情空心
    2021-01-30 03:54

    I liked Altus answer, but I would like to have more breakpoints. So I've created a simple method with some breakpoints using FlexLayout ObservableMedia service instead of onResize:

    import { AfterContentInit, Component, ViewChild } from '@angular/core';
    
    import { MediaChange, ObservableMedia } from '@angular/flex-layout';
    import { MatGridList } from '@angular/material';
    
    @Component({
      selector: 'app-grid',
      templateUrl: './grid.component.html',
      styleUrls: ['./grid.component.css']
    })
    export class GridComponent implements AfterContentInit {
      @ViewChild('grid') grid: MatGridList;
    
      gridByBreakpoint = {
        xl: 8,
        lg: 6,
        md: 4,
        sm: 2,
        xs: 1
      }
    
      constructor(private observableMedia: ObservableMedia) {}
    
      ngAfterContentInit() {
        this.observableMedia.asObservable().subscribe((change: MediaChange) => {
          this.grid.cols = this.gridByBreakpoint[change.mqAlias];
        });
      }
    }
    Breakpoint: {{grid.cols}}
    
      1
      2
      3
      4
      5
      6
      7
      8
    

    See https://stackblitz.com/edit/angular-responsive-material-grid-leocaseiro

提交回复
热议问题