Reputation: 111
I have a page that has a grid of html. For each object, I have added an ng-style
with an ID.
In my controller, I need to be able to set the styles dependent upon an object name from a data call.
example "sD3","dD3"
<div id="sD3" data-ng-style="sD3" class="roundabout-rowDcol3"></div>
<div id="dD3" data-ng-style="dD3" class="grid-data-rowDcol3"></div>
Other than using a very large switch in my controller, is there another way I can grab the object and set the styles?
Something like this:
object = {"background-color": style.backgroundColor, color": style.color,};
Upvotes: 0
Views: 51
Reputation: 48968
Use a property accessor on $scope
.
For:
<div id="sD3" data-ng-style="sD3" class="roundabout-rowDcol3"></div>
Use:
var id = "sD3";
$scope[id] = {"background-color": style.backgroundColor, "color": style.color,};
Upvotes: 1