Patrick
Patrick

Reputation: 4298

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:

Can someone please let me know how to achieve this dynamically?

Upvotes: 1

Views: 725

Answers (3)

Jon
Jon

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

Rodrigo Garcia
Rodrigo Garcia

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

MSA
MSA

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

Related Questions