2014-09-25 38 views
0

有兩個字段。我需要一個比第二個更小,第二個比第一個更多,同時通過驗證。具有最小/最大參數的驗證號碼

但是,在進入第一個號碼時不保存在模型(保存爲未定義),因爲沒有通過驗證條件「最大」

對我重要的是鍵盤輸入而不是按鈕

有人能夠幫我解決這個問題?

<td><input type="number" class="form-control input-sm" ng-model="item.low" max="{{item.high-1}}" required></td> 
<td><input type="number" class="form-control input-sm" ng-model="item.high" min="{{item.low+1}}" required></td> 

回答

0

它比我想象

我只是刪除測試Max在第一輸入端,他是不必要 和驗證是成功的,數據是正確的

容易
<td><input type="number" class="form-control input-sm" ng-model="item.low" required></td> 
<td><input type="number" class="form-control input-sm" ng-model="item.high" min="{{item.low+1}}" required></td> 

ty all for help

0

您是否嘗試初始化控制器中item.low和item.high的值?

<!DOCTYPE html> 
 
<html data-ng-app> 
 

 
    <head> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script> 
 
    <link rel="stylesheet" href="style.css" /> 
 
    <script src="script.js"></script> 
 
    </head> 
 

 
    <body ng-init="item.low=0;item.high=1;"> 
 
    <input type="number" class="form-control input-sm" ng-model="item.low" max="{{item.high-1}}" required> 
 
    <input type="number" class="form-control input-sm" ng-model="item.high" min="{{item.low+1}}" required> 
 
    <p>item.high={{item.high}}</p> 
 
    <p>item.low={{item.low}}</p> 
 
    </body> 
 

 
</html>

+0

是的,我設置在低0和高1. 在你的例子有這個問題。 重要的是鍵盤輸入,而不是按鈕 – zam 2014-09-25 16:55:24

相關問題