2016-12-06 57 views

回答

5

如果你在談論小了並向下和向下箭頭在小時,分鐘和(可選)秒輸入字段之上和之下,實際上您想設置show-spinners="false"上的指令。

<div uib-timepicker ng-model="myDate" show-spinners="false"></div>

arrowkeys設置是隻爲你是否可以按上下,而專注於文本字段來增加或減少的數值範圍之內鍵盤上的箭頭。

+1

混淆了'arrowkeys'和'show-spinners'。,thnkz的答案 –

0

其實有一個小誤會從我們身邊發生的關於uib-timepickerarrowkeys屬性。實際上,當設置arrowkeys="false"不會隱藏箭頭鍵,而是會阻止文本框內的向上和向下箭頭鍵事件。在設置arrowkeys="true"時,可以通過向上和向下箭頭鍵遞增或遞減時間值,將其設置爲false,則不會發生。

arrowkeys(默認值:真):是否用戶可以使用向上/向下arrowkeys 輸入小時&分鐘內,以增加或減小它的值。

要達到您的要求,您需要進行破解。

我不知道這是否是最好的方法,但隱藏向上和向下的箭頭呢。如果這可以解決您的問題,我附上了一個示例代碼。

<!doctype html> 
 
<html ng-app="ui.bootstrap.demo"> 
 

 
<head> 
 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular.min.js"></script> 
 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular-animate.min.js"></script> 
 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-sanitize/1.5.9/angular-sanitize.min.js"></script> 
 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.3.0/ui-bootstrap-tpls.min.js"></script> 
 
    <script> 
 
     angular.module('ui.bootstrap.demo', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']); 
 
     angular.module('ui.bootstrap.demo').controller('TimepickerDemoCtrl', function ($scope, $log) { 
 
      $scope.mytime = new Date(); 
 

 
      $scope.hstep = 1; 
 
      $scope.mstep = 15; 
 

 
      $scope.options = { 
 
       hstep: [1, 2, 3], 
 
       mstep: [1, 5, 10, 15, 25, 30] 
 
      }; 
 

 
      $scope.ismeridian = true; 
 
      $scope.toggleMode = function() { 
 
       $scope.ismeridian = !$scope.ismeridian; 
 
      }; 
 

 
      $scope.update = function() { 
 
       var d = new Date(); 
 
       d.setHours(14); 
 
       d.setMinutes(0); 
 
       $scope.mytime = d; 
 
      }; 
 

 
      $scope.changed = function() { 
 
       $log.log('Time changed to: ' + $scope.mytime); 
 
      }; 
 

 
      $scope.clear = function() { 
 
       $scope.mytime = null; 
 
      }; 
 
     }); 
 
    </script> 
 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
 
    <style> 
 
     .timepickercontainer .uib-timepicker .btn-link { 
 
      display: none; 
 
     } 
 
    </style> 
 
</head> 
 

 
<body> 
 

 
    <div ng-controller="TimepickerDemoCtrl"> 
 
     <div class="timepickercontainer"> 
 
      <div uib-timepicker ng-model="mytime" ng-change="changed()" arrowkeys="false" hour-step="hstep" minute-step="mstep" show-meridian="false"></div> 
 
     </div> 
 
     <pre class="alert alert-info">Time is: {{mytime | date:'shortTime' }}</pre> 
 

 
     <div class="row"> 
 
      <div class="col-xs-6"> 
 
       Hours step is: 
 
       <select class="form-control" ng-model="hstep" ng-options="opt for opt in options.hstep"></select> 
 
      </div> 
 
      <div class="col-xs-6"> 
 
       Minutes step is: 
 
       <select class="form-control" ng-model="mstep" ng-options="opt for opt in options.mstep"></select> 
 
      </div> 
 
     </div> 
 

 
     <hr> 
 

 
     <button type="button" class="btn btn-info" ng-click="toggleMode()">12H/24H</button> 
 
     <button type="button" class="btn btn-default" ng-click="update()">Set to 14:00</button> 
 
     <button type="button" class="btn btn-danger" ng-click="clear()">Clear</button> 
 

 
    </div> 
 
</body> 
 

 
</html>

只需添加一個div一類的時間選擇器的容器說timepickercontainer

然後設置

.timepickercontainer .uib-timepicker .btn-link { 
    display: none; 
} 
+0

謝謝,但它像一個黑客,我希望有更清潔的解決方案。這必定是角度引導團隊的一個錯誤。他們在文檔中明確指出可以隱藏箭頭鍵。 – DennyHiu

+0

在角度文檔中,它聲明可以防止輸入字段內的箭頭鍵事件。 – Nitheesh