角度2背景图像不渲染

时间:2017-09-27 22:36:40

标签: html css angular angular-cli

我有一个Angular 2应用程序,目前只有一个组件。 对于整个页面,我想在页面上渲染背景图像。我做了以下事情: app.component.html

<dashboard class="dash"></dashboard>

app.component.css

.dash {
    background-image: url("../assets/images/background/sligo.jpg");
}

在chrome中的开发工具中,图像显示,但在实际视图中,它仍显示空白屏幕。我错过了什么? 下面的剪辑显示了控制台输出和主视图。

enter image description here

其他信息;这是我的package.json和文件夹结构enter image description here

的剪辑

enter image description here

1 个答案:

答案 0 :(得分:3)

您需要在assets中正确指定root.angular-cli.json属性,例如:

enter image description here

我项目的结构:

enter image description here

您应该使用content代替background-image,如下所示:

.dash {
    content: url(../assets/images/background/sligo.jpg);
}