简体   繁体   English

查询dom中的angularjs对象

[英]Querying the dom for an angularjs object

I have a page that has a grid of html. 我有一个具有html网格的页面。 For each object, I have added an ng-style with an ID. 对于每个对象,我都添加了带有ID的ng-style

In my controller, I need to be able to set the styles dependent upon an object name from a data call. 在我的控制器中,我需要能够根据数据调用中的对象名称来设置样式。

example "sD3","dD3" 例如"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 . $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,};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM