1

I am having an with using the ng-style directive. I want to create add a button to my ng-repeat which is css sprite. If i include the sprite normal way my element inspector has a good old moan. from the information i gather from the Angular documentation

i thought it was as simple as the following:

<button ng-style="{'background-image':'url:('/img/Myimage.png')'}">test</button>

However i am receiving a snytax error message from this line of code. Does anyone know the correct method?

NewKidOnTheBlock
  • 1,491
  • 3
  • 16
  • 32

3 Answers3

1
<button ng-style="{'background-image':'url(\'img/MyImage.png\')'}">test</button> 

is the correct way to do it. was missing the escape the quotes in url 'url:(\'/img/Myimage.png\')'

NewKidOnTheBlock
  • 1,491
  • 3
  • 16
  • 32
0

oh,{color:' something',background:'something '}

ng-style="{background:'url(something)'}"

or

ng-style="{'background-image':'url(something)'}"
Denis
  • 45
  • 9
0

Your CSS syntax is incorrect for url, you have extra : and I would remove quotes for the src so the whole property is one string

<button ng-style="{'background-image':'url(/img/Myimage.png)'}">test</button>

I really don't undertsand why you would use ng-style for this. A simple CSS rule and class would make more sense since you aren't evaluating anything

charlietfl
  • 170,828
  • 13
  • 121
  • 150