Estoy calculando las diferencias entre 2 valores y luego almacenando ese valor en una variable llamada " allCallsNet ", quiero alternar una clase en función de si el número es un número positivo o negativo en mi HTML, usando AngularJS Expressions
Ejemplo:
{allCallsNet=allCallsWeek1 - allCallsWeek2;""} <p ng-class"{{positive: (allCallsNet.value != 'Negative')}}">{{allCallsNet}}</p>Y si también necesita ayuda para verificar el signo de número, esto podría ayudar
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>Prueba esto:
<p [class.positive]="allCallsNet.value != 'Negative'" >{{allCallsNet}}</p>