2014-12-05 104 views
0

我有2个文本框控件“低”和“高”。高场不应该接受的值大于低较小的,我这样做验证,在AngularJS中输入验证

<input id="txtLow" class="txtCell" ng-model='data.low'> 
<input id="txtHigh" class="txtCell" ng-model='data.high'> 
<button id="btnSave" ng-click="saveData()">Save</button> 
<label ng-show="isInvalid()" class="ErrorMsg">High should be greater than Low</label> 

在我的控制器,

$scope.saveData = function() { 
      if (!$scope.isInvalid()) { 
       ......... 
      } 
     }; 
$scope.isInvalid = function() { 
      return $scope.data.low > $scope.data.high; 
     }; 

这是工作的罚款。但我需要将文本框的边框颜色更改为红色,而不是显示标签消息。

+1

创建所需的造型和使用NG-类= “{ '你的类':isInvalid()}” – Rasalom 2014-12-05 11:14:48

+0

谢谢Rasalom! – Dosti 2014-12-05 11:55:02

+0

其实@Kutyel提供的答案更好;) – Rasalom 2014-12-05 12:17:49

回答

2

如果没有CSS文件,然后在html中添加此类似这样的

<label ng-show="isInvalid()" class="ErrorMsg" style='class = red;'>High should be greater than Low</label>