2016-12-13 2 views
-1

ページ上にロードすることができます。角度UIB日付ピッカーを使用して2ヶ月のカレンダーを表示できます。ここで角度UIB日付ピッカーで複数の月を表示することができます

はHTMLである:ここでは

<html ng-app="ui.bootstrap.demo"> 
    <head> 
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js"></script> 
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.3.1.js"></script> 
    <script src="example.js"></script> 
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> 
    </head> 
    <body> 
<div ng-controller="DatepickerDemoCtrl"> 
     <div uib-datepicker ng-model="dt" datepicker-options="options"></div> 
    </div> 
    </body> 
</html> 

はjsのコードは次のとおりです。

angular.module('ui.bootstrap.demo', ['ui.bootstrap']); 
angular.module('ui.bootstrap.demo').controller('DatepickerDemoCtrl', function ($scope) { 
    $scope.today = function() { 
    $scope.dt = new Date(); 
    }; 
    $scope.today(); 

    $scope.clear = function() { 
    $scope.dt = null; 
    }; 

    $scope.options = { 
    numberOfMonths: 2, 
    customClass: getDayClass, 
    minDate: new Date(), 
    showWeeks: true 
    }; 

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

    $scope.toggleMin = function() { 
    $scope.options.minDate = $scope.options.minDate ? null : new Date(); 
    }; 

    $scope.toggleMin(); 

    $scope.setDate = function(year, month, day) { 
    $scope.dt = new Date(year, month, day); 
    }; 

    var tomorrow = new Date(); 
    tomorrow.setDate(tomorrow.getDate() + 1); 
    var afterTomorrow = new Date(tomorrow); 
    afterTomorrow.setDate(tomorrow.getDate() + 1); 
    $scope.events = [ 
    { 
     date: tomorrow, 
     status: 'full' 
    }, 
    { 
     date: afterTomorrow, 
     status: 'partially' 
    } 
    ]; 

    function getDayClass(data) { 
    var date = data.date, 
     mode = data.mode; 
    if (mode === 'day') { 
     var dayToCheck = new Date(date).setHours(0,0,0,0); 

     for (var i = 0; i < $scope.events.length; i++) { 
     var currentDay = new Date($scope.events[i].date).setHours(0,0,0,0); 

     if (dayToCheck === currentDay) { 
      return $scope.events[i].status; 
     } 
     } 
    } 

    return ''; 
    } 
}); 

Plunkerリンク:plunker以上から

https://plnkr.co/edit/?p=preview

これだけ一ヶ月ロードされますカレンダー。二ヶ月カレンダー添付plunkerを用いたアプローチの同種探しenter image description here

を表示する画面を取り付け

+0

これを試してみてくださいます。http://stackoverflow.com/質問/ 33067731 /表示中 - 2ヶ月間の角の日付ピッカー – deChristo

答えて

0

numberOfMonthsプロパティはuib-datepickerでサポートされていません。そのことについては

おそらく最も簡単な方法は、以下の例のようにdatepickerコントロールの2つのインスタンスを配置するようになります:

angular.module('ui.bootstrap.demo', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']); 
 
angular.module('ui.bootstrap.demo').controller('DatepickerDemoCtrl', function ($scope) { 
 
    
 
    $scope.options = { 
 
    }; 
 

 
    $scope.startDate= new Date(); 
 
    $scope.endDate = new Date($scope.startDate.getFullYear(), $scope.startDate.getMonth()+1, 1); 
 
});
.well-sm { 
 
    float: left; 
 
    width: 310px; 
 
}
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js"></script> 
 
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-animate.js"></script> 
 
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-sanitize.js"></script> 
 
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.3.1.js"></script> 
 
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> 
 

 
<div ng-app="ui.bootstrap.demo" ng-controller="DatepickerDemoCtrl"> 
 
    <h4>Months range</h4> 
 
    <div> 
 
     <div uib-datepicker ng-model="startDate" class="well well-sm" datepicker-options="options"></div> 
 
     <div uib-datepicker ng-model="endDate" class="well well-sm" datepicker-options="options"></div> 
 
    </div> 
 
    
 
</div>

関連する問題