Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
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 answers
Answer question

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 Report

0

Try this:

<p [class.positive]="allCallsNet.value != 'Negative'" >{{allCallsNet}}</p>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!