Sam Roberts
Sam Roberts

Reputation: 185

Background image external link URL is not working with ng-style

I'm having some issues with ng-style. Here's the code I have at the moment

ng-style="{'background-image': 'url(http://s3-us-west-1.amazonaws.com/'+ event.image2)'}"

The above isn't working, (I have had to remove the bucket name for reasons), but the code works if I have it like this:

ng-style="{'background': 'orange'}"

This is displaying fine. Why is the URL method not working?

Upvotes: 0

Views: 273

Answers (2)

Shay
Shay

Reputation: 104

I guess event is a variable in your scope, in that case it's just a small typo:


ng-style="{'background-image': 'url(http://s3-us-west-1.amazonaws.com/' + event.image2 + ')'}"

Upvotes: 0

Shashank Agrawal
Shashank Agrawal

Reputation: 25797

You can write like this instead on the element:

<div style="background-image: url('http://s3-us-west-1.amazonaws.com/{{event.image2}}')"></div>

Upvotes: 1

Related Questions