Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Angular 4 background image?

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> 
like image 222
Manihtraa Avatar asked Aug 11 '17 10:08

Manihtraa


People also ask

Why isn t my background image showing up in CSS?

Make sure the image path is set correctly in the background-image url. Once you have made sure that your CSS file is linked correctly, also check that the image itself is set correctly. Again, you will want to open your code inspector in the browser to check.


1 Answers

You can use ngStyle to set background for a div

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

or you can also use built in background style:

<div [style.background-image]="'url(/images/' + trls.img + ')'"></div> 
like image 125
Akash Agrawal Avatar answered Oct 02 '22 21:10

Akash Agrawal