The pipe ' ' could not be found angular2 custom pipe

后端 未结 9 1105
时光说笑
时光说笑 2020-11-27 14:33

I can\'t seem to fix this error. I have a search bar and an ngFor. I am trying to filter the array using a custom pipe like this:



        
9条回答
  •  渐次进展
    2020-11-27 15:08

    import { Component, Pipe, PipeTransform } from '@angular/core';
    
    @Pipe({
      name: 'timePipe'
    })
    export class TimeValuePipe implements PipeTransform {
    
      transform(value: any, args?: any): any {
       var hoursMinutes = value.split(/[.:]/);
      var hours = parseInt(hoursMinutes[0], 10);
      var minutes = hoursMinutes[1] ? parseInt(hoursMinutes[1], 10) : 0;
      console.log('hours ', hours);
      console.log('minutes ', minutes/60);
      return (hours + minutes / 60).toFixed(2);
      }
    }
    @Component({
      selector: 'my-app',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      name = 'Angular';
      order = [
        {
          "order_status": "Still at Shop",
          "order_id": "0:02"
        },
        {
          "order_status": "On the way",
          "order_id": "02:29"
        },
        {
          "order_status": "Delivered",
          "order_id": "16:14"
        },
         {
          "order_status": "Delivered",
          "order_id": "07:30"
        }
      ]
    }
    
    Invoke this module in App.Module.ts file.
    

提交回复
热议问题