Patrick Patrick - 1 year ago 120
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?

Answer Source

You could do this.


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


.negative {
   color: red;
.positive {
    color: green;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download