问题描述:

The numbers are not being picked up presumably because x-offset is not being escaped correctly. What is the right way of putting the values from the controller into ng-style?

The data looks something like this:

{

"item": {

"x-offset": 4,

"y-offset": 5

}

}

and the html:

<div ng-style="{backgroundPosition: -item['x-offset']+'px' -item['y-offset']+'px'}"></div>

网友答案:

You need to enclose the rest of the css string in quotes and concatenate it properly:

<div ng-style="{backgroundPosition: '-' + item['x-offset']+'px -' + item['y-offset']+'px'}"></div>

Here's a working jsfiddle: http://jsfiddle.net/LQpgY/2/

相关阅读:
Top