将ng-class设置为true或false

时间:2016-01-05 15:12:06

标签: angularjs

我有一个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元素。但是当语句不正确时,我无法弄清楚如何删除类。

1 个答案:

答案 0 :(得分:5)

好吧,你需要做的就是像这样清理你的类变量:

1

它将使$scope.newActivities = ''; 重新呈现元素的ng-class属性。