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
I used a BreakpointObserver to achieve this.
See angular documentation : https://material.angular.io/cdk/layout/overview
import { Component, OnInit} from '@angular/core';
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
@Component({
selector: 'app-index',
templateUrl: './index.component.html',
styleUrls: ['./index.component.css']
})
export class IndexComponent implements OnInit {
cols : number;
gridByBreakpoint = {
xl: 3,
lg: 3,
md: 3,
sm: 2,
xs: 1
}
constructor(private breakpointObserver: BreakpointObserver) {
this.breakpointObserver.observe([
Breakpoints.XSmall,
Breakpoints.Small,
Breakpoints.Medium,
Breakpoints.Large,
Breakpoints.XLarge,
]).subscribe(result => {
if (result.matches) {
if (result.breakpoints[Breakpoints.XSmall]) {
this.cols = this.gridByBreakpoint.xs;
}
if (result.breakpoints[Breakpoints.Small]) {
this.cols = this.gridByBreakpoint.sm;
}
if (result.breakpoints[Breakpoints.Medium]) {
this.cols = this.gridByBreakpoint.md;
}
if (result.breakpoints[Breakpoints.Large]) {
this.cols = this.gridByBreakpoint.lg;
}
if (result.breakpoints[Breakpoints.XLarge]) {
this.cols = this.gridByBreakpoint.xl;
}
}
});
}
ngOnInit() {
}
}
1
2
3
4
5
6
7
8