2016-02-08 2 views
0

Я создаю угловую директиву для обработки некоторых функций времени. Я пытаюсь использовать Angular's UI Bootstrap, но я получаю странную ошибку с частью TimePicker. Он покажет мое начальное время (просто по умолчанию на текущее время), но если я попытаюсь нажать стрелки вверх/вниз, чтобы изменить время, он покажет NaN в обоих полях, и когда я проверю дату, он говорит, что это недопустимая дата , Ниже мой код:Угловой UI TimePicker не работает правильно

utilisyncApp.directive("questionDateTime", [ 
 
    "$log", 
 
    function ($log) { 
 
     return { 
 
      restrict: "E", 
 
      templateUrl: "/app/directives/utilisyncItem/utilisyncQuestion/questionDateTime/questionDateTime.html", 
 
      scope: { 
 
       item: '=' 
 
      }, 
 
      link: function ($scope, $element, $attrs) { 
 
       $scope.mStep = 1; 
 
       $scope.hStep = 1; 
 
       $scope.dateFormat = 'dd-MMM-yyyy' 
 
       $scope.popup = { isOpen: false }; 
 
       $scope.dateTime = { time: new Date() }; 
 

 
       $scope.openDate = openDate; 
 
       $scope.changed = changed; 
 

 

 
       init(); 
 

 
       function init() { 
 
        if ($scope.item.question.defaultToCurrent) { 
 
         $scope.dateTime.date = new Date(); 
 
        } 
 
       } 
 

 
       function openDate() { 
 
        $scope.popup.isOpen = true; 
 
       } 
 

 
       function changed() { 
 
        var date = $scope.dateTime.date; 
 
        var time = $scope.dateTime.time; 
 
        if ($scope.item.question.includeTime) { 
 
         $scope.item.value = new Date(date.getFullYear(), date.getMonth(), date.getDay(), time.getHours(), time.getMinutes(), 0); 
 
        } 
 
        else { 
 
         $scope.item.value = new Date(date.getFullYear(), date.getMonth(), date.getDay(), 0, 0, 0); 
 
        } 
 
       } 
 
      } 
 
     }; 
 
    } 
 
]);
<div class="form-group"> 
 
    <p class="input-group"> 
 
     <input type="text" class="form-control" uib-datepicker-popup="{{dateFormat}}" ng-model="dateTime.date" ng-change="changed()" is-open="popup.isOpen" datepicker-options="dateOptions" close-text="Close" /> 
 
     <span class="input-group-btn"> 
 
      <button type="button" class="btn btn-default" ng-click="openDate()"><i class="glyphicon glyphicon-calendar"></i></button> 
 
     </span> 
 
    </p> 
 
    <uib-timepicker ng-if="item.question.includeTime" ng-model="dateTime.date" readonly-input="true" ng-change="changed()" hour-step="hstep" minute-step="mstep" show-meridian="true"></uib-timepicker> 
 
</div>

Похоже, я использую его почти так же, как, например, на их сайте, но это не работает правильно, и я не знаю, почему.

ответ

1

Существует опечатка в этой строке:

<uib-timepicker ng-if="item.question.includeTime" ng-model="dateTime.date" readonly-input="true" ng-change="changed()" hour-step="hStep" minute-step="mStep" show-meridian="true"></uib-timepicker> 

как вы написали

час-ступенчатую = "hstep" минутная шаг = "mstep"

вместо

час-шаг = "hStep "минутная шаг =" mStep "

+0

Ого, что это был, спасибо – GBreen12

Смежные вопросы