AngularJS Datepicker不更新指令

时间:2014-06-19 15:02:10

标签: javascript jquery angularjs twitter-bootstrap datepicker

所以我在AngularJS.org上密切关注文档(在Bootstrap docs的Datepicker部分下),但截至目前,当选择新日期(默认日期除外)时,输入字段会更新,但是不是指令。然而,指令 只有在手动编辑输入字段时才会更新。我是AngularJS的新手,但我到处搜索,似乎无法找到正确的答案。

这是我的控制器:

var QuizCntrl = function ($scope) {

// Sets the default date, making adjustments for meetings that would otherwise land on a weekend date.
$scope.date_selected = new Date();
$scope.date_selected.setHours(0,0,0,0);
if($scope.date_selected.getDay() == 3 || $scope.date_selected.getDay() == 4)
    $scope.date_selected.setDate($scope.date_selected.getDate() + 5);
else
    $scope.date_selected.setDate($scope.date_selected.getDate() + 3);

// Clears selection
$scope.clear = function () {
    $scope.date_selected = null;
};

  // Disable weekend selection
$scope.disabled = function(date, mode) {
    return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );
};

$scope.minDate = new Date();

// $scope.$watch('date_selected', function() {
// });


$scope.open = function($event) {
    $event.preventDefault();
    $event.stopPropagation();

    $scope.opened = true;
};

$scope.dateOptions = {
    formatYear: 'yy',
    startingDay: 0
};

$scope.initDate = new Date('2016-15-20');
$scope.formats = ["shortDate"];
$scope.format = $scope.formats[0];

};

这是我的观点(仅适用于日期选择器):

        <div class="jumbotron" ng-controller="QuizCntrl"">
              <p class="input-group">
                    <input type="text" class="form-control" datepicker-popup="shortDate" ng-model="date_selected" is-open="opened" min-date="minDate" max-date="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" close-text="Close" />
                    <span class="input-group-btn">
                           <button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
                     </span>
              </p>
              {{date_selected | date:'fullDate' }}
         </div>

0 个答案:

没有答案