2016-11-25 13 views
0

角度jsを初めて使用しています。 日付ピッカーを使用して日付カスタムフィルタを実装しようとしています。 私はそれを試しましたが、うまく動かすことはできません。 以下は私のコードです。ここで日付検索フィルターが角度jsで動作していません

<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); 

私は、日付部分からの検索パーツを試してみました。あなたの入力フィールドにfrom_dateセットのモーダル値ので enter image description here

どれ提案.Thankあなた

+0

「return _date;」を使用してください。代わりに "return _date.toUpperCase();" in dateTime関数です。 –

答えて

0

あなたは、日付文字列として、この問題を取得します。テーブルの列で使用したのと同じフォーマットで日付をフォーマットする必要があります

var from_date = $filter('date')($scope.from_date, 'MMM-dd-yyyy'); 
$scope.invoice.filter({ created: from_date }); 
関連する問題