这是我的问题-我不能实现ng-class='{activeTag: $chip.active}'到<md-chip></md-chip>。我尝试将这个指令添加到<md-chips></md-chips>中,但它不起作用(因为$chip不在当前范围内)。我也可以将这个ng-class添加到md-chip-template中,但是在视觉上它不是我想要的,我需要标记中的所有东西的背光。顺便说一下,<md-chip></md-chip>是在md-chips指令中动态创建的。也许有人面临这个问题,或者只是知道解决办法。谢谢。
这里是我的控制器
controller('ChipsController', function($scope) {
$scope.tags = [
{
id: 1,
name: 'Pop',
active: false
},
{
id: 2,
name: 'Rock',
active: true
},
{
id: 3,
name: 'Reggie',
active: false
}
];
});我的观点
<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>
My css
.activeTag {
background: rgba(85, 107, 47, 0.66) !important;
color: white !important;
}这是柱塞
发布于 2016-02-06 07:36:41
我可能更喜欢使用自定义指令,它将特殊类添加到您的chip中
.directive('myChip', function(){
return {
restrict: 'EA',
link: function(scope, elem, attrs) {
var myChip = elem.parent().parent();
myChip.addClass('_active');
scope.$watch(function(){
return scope.$chip.active
}, function(newVal){
if (newVal) {
myChip.addClass('_active');
} else {
myChip.removeClass('_active');
}
})
}
}
})模板
<md-chip-template ng-class="{'activeTag': $chip.active}" style="cursor: pointer;" my-chip>样式
.md-chip._active {
background: rgba(85, 107, 47, 0.66) !important;
color: white !important;
}http://plnkr.co/edit/vv2SvH1gNj3OIh1oaqvV?p=preview
https://stackoverflow.com/questions/35238286
复制相似问题