2014-12-05 81 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>