我有一个Icon元素,我想根据其他内容切换类,
%i.fa.fa-bell{"ng-class" => "newActivities"}
我的控制器中有一个if / else语句,
var activities = $scope.activities
var init = function(){
var hasValue = activities.some(function(obj) { return obj.viewed == "uncheck" });
console.log (hasValue)
if (hasValue == true){
checked = true ;
$scope.newActivities = 'newActivities';
}
}
$scope.viewActivities = function (){
angular.forEach(activities, function (activitie) {
viewActivities.update({
viewed: `check`,
id: activitie.id
}).then(init);
});
$scope.newActivities = '';
}
现在发生的是,当if值为true时,$scope.newActivities
会将newActities
添加到ng-class元素。但是当语句不正确时,我无法弄清楚如何删除类。
答案 0 :(得分:5)
好吧,你需要做的就是像这样清理你的类变量:
1
它将使$scope.newActivities = '';
重新呈现元素的ng-class
属性。