我正在計算 2 個值之間的差異,然后將該值存盤在一個名為“ allCallsNet ”的變數中,我想使用 AngularJS 運算式根據我的 HTML 中的數字是正數還是負數來切換一個類
例子:
{allCallsNet=allCallsWeek1 - allCallsWeek2;""}
<p ng-class"{{positive: (allCallsNet.value != 'Negative')}}">{{allCallsNet}}</p>
uj5u.com熱心網友回復:
如果您還需要幫助檢查數字符號,這可能會有所幫助
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>
uj5u.com熱心網友回復:
嘗試這個:
<p [class.positive]="allCallsNet.value != 'Negative'" >{{allCallsNet}}</p>
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/371071.html
上一篇:在某些條件下隱藏輸入欄位
