首页 > 解决方案 > 找不到不同的支持对象 NgStyle backgroundImage

问题描述

我正在尝试使用 Angular 在 div 中显示图像

我有:

<div 
  ngStyle="{'backgroundImage': 'url({{getImage()}})'}"
>
  <div class="text-wrapper">
    text
  </div>
</div>

我正在通过的图片的地址:

  ngOnInit() {
    this.fullImagePath = 'assets/hackaton_home.png';
  }

  getImage() {
    return this.fullImagePath;
  }

该图像位于文件夹 assets 中。

我得到的错误是:

在此处输入图像描述

有什么帮助吗?

标签: angular

解决方案


<div [ngStyle]="{ 'background-image': 'url(' + fullImagePath+ ')'}"></div>

推荐阅读