Reputation: 4298
I have a input type number in AngularJS as follows...
<input type="number"></input>
I want to achieve the following:
If user enters a positive value, it should display the same font and color
If the user displays a negative value, it should display font color in red indicating it is a negative number
Can someone please let me know how to achieve this dynamically?
Upvotes: 1
Views: 725
Reputation: 2671
You could do this.
HTML
<input type="number" ng-class="{negative: amount < 0, positive: amount > 0}" ng-model="amount"/>
CSS
.negative {
color: red;
}
.positive {
color: green;
}
Upvotes: 1
Reputation: 58
<input type="number" ng-model="number">
<label ng-show="number > 0" style="color:green;">You are Correct</label>
<label ng-show="number < 0" style="color:red;">Your number is negative</label>
Upvotes: 1
Reputation: 134
<input type="number" ng-change="amountChanged()" ng-style="myStyle.color" ng-model="amount"/>
$scope.myStyle= {};
$scope.amountChanged = function () {
if($scope.amount < 0)
{
$scope.myStyle.color= {"color":"green"};
}
else
{
$scope.myStyle.color= {"color":"blue"};
}
}
Hope it helps.
Upvotes: 1