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,};
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,};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.