如何以单一形式使用多个Angular UI Bootstrap Datepicker?

如何以单一形式使用多个Angular UI Bootstrap Datepicker?,第1张

如何以单一形式使用多个Angular UI Bootstrap Datepicker?

我有一种形式的30个控制器,没问题。如果需要在ng-repeat上使用相同的概念

 <label>First Date</label>      <div >     <input type="text"  datepicker-popup="{{format}}"  name="dt" ng-model="formData.dt" is-open="datepickers.dt"  datepicker-options="dateOptions" ng-required="true"  close-text="Close" />      <span >        <button  ng-click="open($event,'dt')"> <i ></i></button>      </span>    </div> <label>Second Date</label>      <div >     <input type="text"  datepicker-popup="{{format}}"  name="dtSecond" ng-model="formData.dtSecond"  is-open="datepickers.dtSecond" datepicker-options="dateOptions"  ng-required="true" close-text="Close" />      <span >        <button  ng-click="open($event,'dtSecond')"> <i ></i></button>      </span>    </div>myApp.controller('DatePickrCntrl', function ($scope) {      $scope.datepickers = {        dt: false,        dtSecond: false      }      $scope.today = function() {        $scope.formData.dt = new Date();        // ***** Q1  *****        $scope.formData.dtSecond = new Date();      };      $scope.today();      $scope.showWeeks = true;      $scope.toggleWeeks = function () {        $scope.showWeeks = ! $scope.showWeeks;      };      $scope.clear = function () {        $scope.dt = null;      };      // Disable weekend selection      $scope.disabled = function(date, mode) {        return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );      };      $scope.toggleMin = function() {        $scope.minDate = ( $scope.minDate ) ? null : new Date();      };      $scope.toggleMin();      $scope.open = function($event, which) {        $event.preventDefault();        $event.stopPropagation();        $scope.datepickers[which]= true;      };      $scope.dateOptions = {        'year-format': "'yy'",        'starting-day': 1      };      $scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'shortDate'];      $scope.format = $scope.formats[0];}); // ***** Q2 ***** somemodel can be just an array [1,2,3,4,5] <div ng-repeat="o in somemodel"> <label>Date Label</label>      <div >     <input type="text"  datepicker-popup="{{format}}" name="dt{{o}}" ng-model="datepickers.data[o]"  is-open="datepickers.isopen[o]" datepicker-options="datepickers.option"  ng-required="true" close-text="Close" />      <span >        <button  ng-click="open($event,o)"> <i ></i></button>      </span>    </div>  </div>myApp.controller('DatePickrCntrl', function ($scope) {      $scope.datepickers = {        data: {},        options: { 'year-format': "'yy'", 'starting-day': 1        },        isopen: {}      }      $http.get("get/data/for/some/model", function(result) {         $scope.somemodel = result;         for (var i = 0; i < result.length; i++) {$scope.datepickers.isopen[result] = false;$scope.datepickers.data[result] = new Date(); //set default date.         }      });  // fill in rest of the function});


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5642063.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存