Javascript 关于角材料芯片的ng类
我想根据我的键值类型为具有“活动”标志的芯片创建一些背光,我为这些芯片创建了一个Javascript 关于角材料芯片的ng类,javascript,css,angularjs,angular-material,md-chip,Javascript,Css,Angularjs,Angular Material,Md Chip,我想根据我的键值类型为具有“活动”标志的芯片创建一些背光,我为这些芯片创建了一个ng class=“{activeTag:$chip.active}”,但它不起作用。如何在动态创建的md芯片上添加这个ng类 查看 <md-chips class="custom-chips selected" ng-model="tags" ng-class="{activeTag: $chip.active}" readonly="true"> <md-chip-template styl
ng class=“{activeTag:$chip.active}”
,但它不起作用。如何在动态创建的md芯片上添加这个ng类
查看
<md-chips class="custom-chips selected" ng-model="tags" ng-class="{activeTag: $chip.active}" readonly="true">
<md-chip-template style="cursor: pointer;" >
<a ui-sref="">
<strong>{{$chip.id}}</strong>
<em>({{$chip.name}})</em>
</a>
</md-chip-template>
</md-chips>
css
.activeTag md-chip{
background: rgba(85, 107, 47, 0.66) !important;
color: white !important;
}
您的问题可能是您试图在
md chips
元素上使用$chip
。这是容器而不是中继器。模板中的内容是重复的内容
我对MD组件不太熟悉,但您离使用
$chip
还有一到两级的距离。将tour css修改为just.activetag,并将ng类添加到md芯片模板中
CSS:
html:
<md-chips class="custom-chips selected" ng-model="tags" readonly="true">
<md-chip-template ng-class="{activeTag: $chip.active}" style="cursor: pointer;" >
<a ui-sref="">
<strong>{{$chip.id}}</strong>
<em>({{$chip.name}})</em>
</a>
</md-chip-template>
</md-chips>
{{$chip.id}
({{$chip.name}})
谢谢@Atticus,你说得对。我需要找到另一种方法将这个类实现到md芯片上,但这是另一个问题。在这种情况下,我们将只在md芯片模板中使用这个类。从视觉上看,这不是我想要的,我需要标签中所有东西的背光
.activeTag {
background: rgba(85, 107, 47, 0.66) !important;
color: white !important;
}
<md-chips class="custom-chips selected" ng-model="tags" readonly="true">
<md-chip-template ng-class="{activeTag: $chip.active}" style="cursor: pointer;" >
<a ui-sref="">
<strong>{{$chip.id}}</strong>
<em>({{$chip.name}})</em>
</a>
</md-chip-template>
</md-chips>