首页 > 解决方案 > Angular - 我如何将 Api 中的图像设置为背景图像

问题描述

我尝试将从我的 api 获得的图像设置为来自我的标题的背景图像。但它不会按预期工作......

这是我的代码:

    <div class="container">
        <div class="header" [ngStyle]="{background: 'url('userProfile.headerImagePath')'}">
        ...

css

.header {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 500px;
    min-width: 100%;
    background-color: yellowgreen;
}

标签: cssangular

解决方案


请使用以下代码。

        <div class="header" [ngStyle]="{background: 'url('+userProfile.headerImagePath+')'}">
        ...

推荐阅读