我使用 Angular 原理图 ( ng generate @angular/material:dashboard) 在 component.ts 文件中生成以下代码:
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 }
];
})
);
但是我无法理解它在做什么。有几个组件会引起一些混乱:
=>语法在做什么?因为它是一个符号,所以我很难想出一个谷歌搜索。编辑:这个问题的答案在这里- 地图功能在做什么?我理解地图,但通常我将一个函数映射到一组值。这就是这里发生的事情吗?换句话说,什么被映射到什么?
- 管道功能在这里做什么?从这篇文章我明白:
pipe() 函数将要组合的函数作为其参数,并返回一个新函数,该函数在执行时按顺序运行组合函数。
但是,我不清楚组合函数在这里做什么。