Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
65
rated 0 times [  66] [ 1]  / answers: 1 / hits: 199650  / 7 Years ago, fri, august 11, 2017, 12:00:00

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>

More From » angular

 Answers
11

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>

[#56799] Tuesday, August 8, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kinsley

Total Points: 352
Total Questions: 84
Total Answers: 94

Location: Denmark
Member since Tue, Jul 19, 2022
2 Years ago
;