日期搜索过滤器在角度js中不起作用

时间:2016-11-25 05:26:52

标签: javascript angularjs angular-filters

我是棱角分明的新手。 我正在尝试使用日期选择器实现日期自定义过滤器。 我试过了,但我不知道要解决这个问题。 以下是我的代码。

  <div class="col-sm-2 m-b-xs">
    <input type="text" name="from_date" class="form-control" placeholder="From" date-time view="date" auto-close="true" min-view="date" ng-model="from_date"  format="MMM-DD-YYYY" readonly />
      </div>
   <tr class="gradeU" ng-repeat="x in invoice | filter:{created : from_date}">       
  <td style="text-align: center;">{{ x.created | datetime }}</td>      
</tr> 
JS SECTION 
function InvoiceControllers($scope, $stateParams, $http, $state) {
    $scope.filterData = {};
    $scope.invoice_listing = function (data) {
        var json = (function () {
            var json = null;
            $.ajax({
                'async': false,
                'global': false,
                'url': 'invoices/listing_invoice',
                'data': data,
                'dataType': "json",
                'success': function (data) {
                    // alert(data);
                    json = data;
                }
            });
            return json;
        })();
        //$scope.formData = {value : json};
        $scope.invoice = json;
    };
    var data = {};
    $scope.invoice_listing(data);

    $scope.filter_invoice = function () {
        var data = $scope.filterData;
        $scope.invoice_listing(data);
    };


}

function dateTime($filter) {
    return function (input) {
        if (input == null) {
            return "";
        }

        var _date = $filter('date')(new Date(input), 'MMM-dd-yyyy');
        return _date.toUpperCase();

    };
}

angular
        .module('inspinia')

        .controller('InvoiceControllers', InvoiceControllers)

        .filter('datetime', dateTime);

这里我从日期部分尝试了搜索部分。 enter image description here

任何建议。谢谢你

1 个答案:

答案 0 :(得分:0)

您遇到此问题,因为在输入字段from_date中将模态值设置为日期字符串。您需要使用表格列

中使用的相同格式设置日期格式
var from_date = $filter('date')($scope.from_date, 'MMM-dd-yyyy');
$scope.invoice.filter({ created: from_date });
相关问题