Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
Apply class based on integer value in an AngularJS expression

I'm calculating differences between 2 values then storing that value in a variable named "allCallsNet", I want to toggle a class based on if the number is a Positive or Negative number in my HTML, using AngularJS Expressions

Example:

{allCallsNet=allCallsWeek1 - allCallsWeek2;""}

<p ng-class"{{positive: (allCallsNet.value != 'Negative')}}">{{allCallsNet}}</p>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

And if you also need help checking the number sign this could help

angular.module('Stack', []).controller('MainCtrl', function($scope) {
  $scope.allCallsNet = 0;
  $scope.add = function() {
    $scope.allCallsNet += 1;
  }
  $scope.sub = function() {
    $scope.allCallsNet -= 1;
  }
});
.negative {
  color: red;
}

.positive {
  color: green;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="Stack" ng-controller="MainCtrl">
  <!-- You can use the ternary operator, to exchange between classes -->
  <p ng-class="allCallsNet > 0 ? 'positive' : 'negative'">Start editing and see your changes reflected here!</p>
  <button ng-click="add()">Add</button>
  <button ng-click="sub()">Subtract</button>
  <p>{{ allCallsNet }}</p>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

Try this:

<p [class.positive]="allCallsNet.value != 'Negative'" >{{allCallsNet}}</p>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda