angularionic-frameworkfilterionic2migrating

how to use $filter in ionic 2


I'm migrating an Ionic App to Ionic 2 App, since I'm not expert on Ionic 2 I got some problems doing it.

My question now is if there is any function like $filter in Ionic 2.

This is the code from Ionic 1 that I need to convert:

 var group = {};
            for (var i = 0; i < orders.length; i++) {
                var dateObj = new Date(orders[i].DocumentDate);

                var date = $filter('date')(dateObj, 'dd-MM-yyyy');

                dateObj = new Date(orders[i].EDIMessageDate);
                orders[i].time = $filter('date')(dateObj, 'HH:mm');

                if (angular.isDefined(group[date])) {

                    group[date].push(orders[i]);
                } else {
                    group[date] = [orders[i]]
                }
            }

So far I have done this:

let group = {};
  for(let  i = 0; i<orders.length; i++){

      let dateObj = new Date(orders[i].DocumentDate);
      let date = $filter('date')(dateObj, 'dd-MM-yyy');

      dateObj = new Date(orders[i].EDIMessageDate);
      orders[i].time = $filter('date')(dateObj, 'HH:mm');

      if(group[date] != null)
          group[date].push(orders[i]);
      else
          group[date] = [orders[i]];

  }

But I don't know how I can replace:

$filter('date')(dateObj, 'dd-MM-yyy');

To Ionic 2. Any advice?

Thank you for the help.


Solution

  • You have 2 options here.

    Option 1: You can use momentjs

    Option 2: You can use Angular DatePipe.

    {{yourDate | date: 'dd/MM/yyyy'}}