0

Suppose we have already the first image.

.bg{
    background-image: url('img/bg1.png');
}

Then we wanna add another image img/bg2.png using Angular 2. How could we do that?

I tried to use

<div [style.background-image]="getBg()"></div>

while

getBg(){
    return "url('img/bg2.png')";
}

However, it will replace the bg1.png. So how could I add another background image to the div above? Thanks.

edit: I know we should use comma, but how could we get the first image using Angular 2?

Zhipeng YANG
  • 797
  • 9
  • 18

1 Answers1

0

You need to pass a comma-separated list of URLs:

getBg(){
    return "url('img/bg1.png'),url('img/bg2.png')";
}

See also Can I have multiple background images using CSS?

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567