如何设置Angular 4背景图像? [英] How to set Angular 4 background image?

查看:209
本文介绍了如何设置Angular 4背景图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以下行来设置背景图像.但是它不起作用.在我的应用程序中不断设置背景图像的方式是什么.

I am trying the following lines to set the background image.but it not works. what are the way set background image in constantly in my application.

app.component.html

<div [ngStyle]="{'background' : 'url(./images/trls.jpg)'}">
    <router-outlet></router-outlet>
    <alert></alert>
</div>

推荐答案

您可以使用 ngStyle 为div设置背景

You can use ngStyle to set background for a div

<div [ngStyle]="{background: 'url(./images/' + trls.img + ')'}"></div>

或者您也可以使用内置的背景样式:

or you can also use built in background style:

<div [style.background]="'url(/images/' + trls.img + ')'"></div>

这篇关于如何设置Angular 4背景图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆