小编Jah*_*eer的帖子

ngStyle指令的角度设置样式

我在这里使用Angular 7。我想渲染一个*ngFor循环内的图像。所有这些图像的高度都不同,因此我想根据返回的数据设置图像的高度。这是参考代码

<div *ngFor="let image of images" class="image-container">
  <img mat-card-image src="{{image.webformatURL}}">
  <p>image height:{{ image.previewHeight }}</p>
</div>
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,我以像素为单位获取了{{ image.previewHeight }}<img>标记的高度。寻找与此相似的解决方案

<img mat-card-image  style="height:{{ image.previewHeight }}" src="{{image.webformatURL}}">
Run Code Online (Sandbox Code Playgroud)

我已经尝试过了,但是在页面上给出了错误。

angular-material angular

1
推荐指数
1
解决办法
62
查看次数

标签 统计

angular ×1

angular-material ×1