我有一个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元素.但是,当语句不正确时,我无法弄清楚如何删除类.
好吧,你需要做的就是清理你的类变量,如下所示:
$scope.newActivities = '';
它将ng-class
重新渲染class
元素的属性.