I used an Angular schematic (ng generate @angular/material:dashboard
) to generate the following code in the component.ts file:
cards = this.breakpointObserver.observe(Breakpoints.Handset).pipe(
map(({ matches }) => {
if (matches) {
return [
{ title: 'Card 1', cols: 1, rows: 1 },
{ title: 'Card 2', cols: 1, rows: 1 },
{ title: 'Card 3', cols: 1, rows: 1 },
{ title: 'Card 4', cols: 1, rows: 1 }
];
}
return [
{ title: 'Card 1', cols: 2, rows: 1 },
{ title: 'Card 2', cols: 1, rows: 1 },
{ title: 'Card 3', cols: 1, rows: 2 },
{ title: 'Card 4', cols: 1, rows: 1 }
];
})
);
However I'm having trouble understanding what it's doing. There are several components that cause some confusion:
- What is the
=>
syntax doing? I had trouble coming up with a Google search since it is a symbol. EDIT: The answer to this is here - What is the map function doing? I understand map, but normally I'm mapping a function to a set of values. Is that what is happening here? Said another way, what is being mapped onto what?
- What is the pipe function doing here? From this post I understand:
The pipe() function takes as its arguments the functions you want to combine, and returns a new function that, when executed, runs the composed functions in sequence.
However it's not clear to me what the composed functions are doing here.