【发布时间】:2014-03-10 10:38:13
【问题描述】:
我的查看代码:
<div ng-repeat = "i in items track by $index">
<myDirective label = "i.labels"> </myDirective>
</div>
部分指令代码:
return {
scope : {
label : '='
}
link : function($scope, elem, attrs){
$scope.$watch('label', function(v){
if(v[1] == "somevalue"){ // apply a css style to this ng-repeat item.}
});
}
}
我想根据v[1] 将css 样式应用于当前元素。 在指令中实现这一目标的“角度方式”是什么?
【问题讨论】:
-
在此处查看指令stackoverflow.com/questions/13294507/…中的数据绑定,只使用样式而不是值
-
@Johnny000 :我在上面实现数据绑定的方式有问题吗?
-
我不知道你为什么要使用watch,但如果你真的不需要,尽量避免使用$watch,因为它不利于性能angular-tips.com/blog/2013/08/removing-the-unneeded-watches
标签: javascript html css angularjs