Patrick Patrick - 3 months ago 11x
AngularJS Question

Input type number in AngularJS

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?


You could do this.


<input type="number" ng-class="{negative: amount < 0, positive: amount > 0}" ng-model="amount"/>


.negative {
   color: red;
.positive {
    color: green;