Angular 如何将图像添加到角网格单元

Angular 如何将图像添加到角网格单元,angular,Angular,我想向其中一个网格添加完整图像。如何将图像添加到网格单元。下面是component.ts文件: export interface Tile { color: string; cols: number; rows: number; text: string; fontSize: string; fontFamily: string; } @Component({ selector: 'grid-list-dynamic-example', templateUrl:

我想向其中一个网格添加完整图像。如何将图像添加到网格单元。下面是component.ts文件:

export interface Tile {
  color: string;
  cols: number;
  rows: number;
  text: string;
  fontSize: string;
  fontFamily: string;
}
@Component({
  selector: 'grid-list-dynamic-example',
  templateUrl: 'grid-list-dynamic-example.html',
  styleUrls: ['grid-list-dynamic-example.css'],
})
export class GridListDynamicExample {
  tiles: Tile[] = [

    { text: 'One', cols: 5, rows: 1, color: 'lightblue', fontSize: '20', 
fontFamily: 'Rubik'},
    { text: 'Two', cols: 3, rows: 1, color: 'lightgreen', fontSize: '20', 
fontFamily: 'Roboto Condensed'},
    { text: 'Three', cols: 2, rows: 2, color: 'lightpink', fontSize: 
'25', fontFamily:  'Rubik'  },
    { text: 'Four', cols: 3, rows: 1, color: '#DDBDF1', fontSize: '30' , 
fontFamily: 'Roboto Condensed' },
{ text: 'Five', cols: 3, rows: 1, color: 'lightblue', fontSize: '35', 
fontFamily:  'Roboto Condensed'},
    { text: 'Six', cols: 2, rows: 1, color: 'lightyellow', fontSize: 
'40',fontFamily: 'Rubik' },
  ];
}
这是html文件:

<mat-grid-list cols="5" rowHeight="20vh" [gutterSize]="'0px'">
  <mat-grid-tile
      *ngFor="let tile of tiles; let i = index"
      [colspan]="tile.cols"
      [rowspan]="tile.rows"
      [style.background]="tile.color"
      [ngStyle]="{'font-size': 'calc(' + tile.fontSize + 'px + 0.5vw)', 
'font-family': tile.fontFamily +', sans-serif;'}"
      [ngClass]="'tile' + i"
   >
    {{tile.text}}
  </mat-grid-tile>
</mat-grid-list>
这是你的电话号码


我能够在ts文件中添加图像作为颜色,但图像只是网格单元中展开的图像的一小部分

检查编辑的StackBlitz示例代码

我就这样改变了你的界面

export interface Tile {
  color: string;
  cols: number;
  rows: number;
  text: string;
  fontSize: string;
  fontFamily: string;
  paddingTop: string;
  marginLeft: string;
  marginRight: string;
  hasImage?: boolean;
  imageUrl?: string;
}
在html内部标记处:

 <ng-container *ngIf="tile.hasImage; else textContainer">
   <img [src]="tile.imageUrl"/>
 </ng-container>

 <ng-template #textContainer>
    {{tile.text}}
  </ng-template>

哪个图像?在哪个牢房?基于时髦的标准?你试过什么?也许这能让你开始?
{... imageUrl: "https://assets.pernod-ricard.com/nz/media_images/test.jpg?hUV74FvXQrWUBk1P2.fBvzoBUmjZ1wct" ,hasImage: true, ...}