【问题标题】:angular-UI datepicker apply date filter in controllerangular-UI datepicker 在控制器中应用日期过滤器
【发布时间】:2015-01-01 06:30:09
【问题描述】:

我正在使用 angular-ui 的日期选择器,我在我的应用程序的许多地方都使用了这个日期选择器,所以我必须在每个控制器中应用日期过滤器。为避免这种情况,我需要在基准日期选择器控制器中应用日期过滤器

点赞$scope.formData.order_date = $filter('date')($scope.formData.order_date, 'dd-MM-yyyy');

基础日期选择器控制器:

controller('DatepickerDemoCtrl', [
    '$scope', function($scope) {
      $scope.today = function() {
        return $scope.dt = new Date();
      };
      $scope.today();
      $scope.showWeeks = true;
      $scope.toggleWeeks = function() {
        return $scope.showWeeks = !$scope.showWeeks;
      };
      $scope.clear = function() {
        return $scope.dt = null;
      };
      $scope.disabled = function(date, mode) {
        return mode === 'day' && (date.getDay() === 0 || date.getDay() === 6);
      };
      $scope.toggleMin = function() {
        var _ref;
        return $scope.minDate = (_ref = $scope.minDate) != null ? _ref : {
          "null": new Date()
        };
      };
      $scope.toggleMin();
      $scope.open = function($event,opened) {
        $event.preventDefault();
        $event.stopPropagation();
        console.log($scope);

        $scope[opened] = true;
      };

      $scope.dateOptions = {
        'year-format': "'yy'",
        'starting-day': 1
      };
      $scope.formats = ['dd-MM-yyyy', 'yyyy/MM/dd', 'shortDate'];
      return $scope.format = $scope.formats[0];
    }
  ]) 

如何在 datepicker 控制器中添加通用日期过滤器?有可能吗?

【问题讨论】:

    标签: angularjs angular-ui


    【解决方案1】:

    如果只是你想做一个基本的日期格式化,你可以直接在 datepicker 标签本身上应用“format-day”、“format-month”和“format-year”元素。请参阅此先前回答的 stackoverflow 问题的解决方案:Angular bootstrap datepicker date format does not format ng-model value。有关详细信息,请参阅文档:http://angular-ui.github.io/bootstrap/

    【讨论】:

    • 我需要用服务器处理。所以它不是基本格式
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多