Angular 8显示图像src作为ng模型存储在变量中

问题描述 投票:0回答:2

我想将图像src显示为动态变量,我在名为displayImage的变量中将默认值声明为字符串:

<div class="col-6 " style="margin-top: 35px;">
  <div class="row">
    <div class="col-6">
      <img src="assets/cardsModels/Anniversaire.png" alt="">
    </div>
  </div>
</div>

**

this.displayedImage = 'assets/cardsModels/Anniversaire.pnf'

this.displayedImage在构造函数中声明,找不到图像,因此无法显示!

html angular image src angular-ngmodel
2个回答
1
投票

只需在displayedImage中使用变量,然后为图像设置src


0
投票

您问题的解决方案是更改html like(使用数据绑定):

© www.soinside.com 2019 - 2024. All rights reserved.