0

i have the following pipe:

import {Pipe, PipeTransform} from '@angular/core';

@Pipe({
    name: 'isInPast'
})
export class IsInPastPipe implements PipeTransform {
    transform(date: Date, time: any) {
        let today = new Date();
        if (date < today) {

            return 'inPast';
        }
        return '';
    }

}

This takes two parameters.

Now i wish to send those in my html but i don't know how. i have tried:

 [ngClass]="isInPast:row.day:task.time"

i have also tried:

 [ngClass]="row.day task.time | isInPast:row.day:task.time"

Can anyone tell me how i can do this?

Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364

3 Answers3

2
import {Pipe, PipeTransform} from '@angular/core';

@Pipe({
    name: 'isInPast'
})
export class IsInPastPipe implements PipeTransform {
    transform(date: Date, time: any) {
        // I don't know what type is at time, let's assume it is Date type.
        let today = time || new Date();
        if (date < today) {
            return 'inPast';
        }
        return '';
    }

}
[ngClass]="row.day | isInPast: task.time"
Hsuan Lee
  • 2,300
  • 1
  • 10
  • 18
1

If you want to toggle the inPast class based on date, implement it like this:

import {Pipe, PipeTransform} from '@angular/core';

@Pipe({
    name: 'isInPast'
})
export class IsInPastPipe implements PipeTransform {
    transform(date: Date, time: any) {
        let today = new Date();
        if (date < today) {

            return true;
        }
        return false;
    }

}

Then apply it like this

 [ngClass]="{'inPast' : row.day | isInPast:task.time }"
Ethan Vu
  • 2,911
  • 9
  • 25
0
{{ yourData | isInPast: 'arg1':'arg2':'arg3'... }}

How do I call an Angular 2 pipe with multiple arguments?

Patricio Vargas
  • 5,236
  • 11
  • 49
  • 100