Filter the date in pt-br at AngularJs?

3

I have a problem with making a filter in AngularJs in a date field.

Below is the html:

<td class="text-center" title="'Data'" filter="{ dataProposta: 'text'}" id="'data'">
    {{p.dataProposta | date: "dd/MM/yyyy"}}
</td>

The view looks like this:

  

No% date% when entering the date in Brazilian format 03/24/2016 , the system does not filter, but if I type 2016-03-24 , I can see the filters made for this date.

    
asked by anonymous 18.07.2018 / 17:50

1 answer

1

You have to do a custom filter, and test the text in the format that is on your screen, because what is coming is in another format and so it does not work.

Example:

var app = angular.module('app', []);
app.controller('ctrl', function($scope) {
  $scope.search = '';
  $scope.list = [{
      id: 1,
      data: '2016-01-01'
    },
    {
      id: 2,
      data: '2016-01-02'
    },
    {
      id: 3,
      data: '2016-01-03'
    },
    {
      id: 4,
      data: '2016-01-03'
    },
  ];
  $scope.listFilter = function(model) {
    if ($scope.search === '') return true;    
    var _data = model.data.split('-').reverse();
    _data = _data.join('/');
    return _data.indexOf($scope.search) !== -1;
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/angular-i18n/1.7.2/angular-locale_pt-br.js"></script>


<div ng-app="app" ng-controller="ctrl">
  <input type="text" ng-model="search" />
  <ul>
    <li ng-repeat="d in list | filter:listFilter">{{d.id}} - {{d.data | date: 'dd/MM/yyyy'}}</li>
  </ul>
</div>
    
18.07.2018 / 19:56