AndrewPoyntz / time-ago-pipe

An Angular pipe for converting a date string into a time ago
MIT License
130 stars 67 forks source link

doesn't work with angular 9 version #33

Open Famin42 opened 4 years ago

Famin42 commented 4 years ago

I have an error in console, when try to import TimeAgoPipe and add to module declarations.

So, little "crutch" like that solved my problem

...
import { TimeAgoPipe } from 'time-ago-pipe';

@Pipe({
    name: 'timeAgo',
    pure: false
})
export class TimeAgoExtendsPipe extends TimeAgoPipe {}

@NgModule({
    declarations: [
        TimeAgoExtendsPipe,
...
Nasun4o commented 4 years ago

Same problem with Angular 9.

benj0c commented 4 years ago

@AndrewPoyntz did you plan to maintain this lib/repository?

wisdomrider commented 4 years ago

same problem

ChaitanyaBabar commented 4 years ago

+1

@Fomin2402 @Nasun4o @wisdomrider Although disabling aot generates build successfully.

CC: @AndrewPoyntz

ganholete commented 4 years ago

+1

sellefrancais commented 4 years ago

Setting Pipe.pure to "true" and I was confirm it works as expected roughly.

tomasalles commented 4 years ago

Setting Pipe.pure to "true" and I was confirm it works as expected roughly.

How would you do that?

ilkeryanizca commented 4 years ago

Does not work with Angular 9. Do you have any suggestions?

andreitruta commented 4 years ago

Does not work with Angular 9. Do you have any suggestions? Hello, ilkeryanizca you must do what Fomin2402 did in his post.

ChaitanyaBabar commented 4 years ago

Setting Pipe.pure to "true" and I was confirm it works as expected roughly.

How would you do that?

Follow the method provided by @Fomin2402 .

Steps

  1. In your current code implementation you remove the reference TimePipeAgo in your NgModules.
  2. Then extend TimePipeAgo to your own custom implementation i.e. TimeAgoExtendsPipe class.
  3. Use the same decorators provided by @Fomin2402 in above code.
PsykotropyK commented 4 years ago

Hello, I have the same issue but using @Fomin2402 code raise an error:

Classes decorated with @Pipe decorator should implement PipeTransform interface.

ilkeryanizca commented 4 years ago

Hello everyone and thanks for your answers. I use 'time-ago-pipe', and it works pretty well. I would recommend. Have a nice day.

P3tronius commented 4 years ago

Seems to be the same issue with JsonPipe.

larsnedb commented 4 years ago

It does work in Angular 9 with one little modification:

import {Pipe, PipeTransform} from '@angular/core';
import {TimeAgoPipe} from 'time-ago-pipe';

@Pipe({
  name: 'timeAgo',
  pure: false
})
export class TimeAgoExtendsPipePipe extends TimeAgoPipe implements PipeTransform {

  transform(value: string): string {
    return super.transform(value);
  }
}

Note that you have to implement PipeTransform in order to not get compilation error on @Pipe. Not sure why I both have to extend a class which implements an interface AND implement the interface. But this TimeAgo has caused me enough troubles now, so I'm happy enough as long as it is working.

eranamarante commented 4 years ago

It does work in Angular 9 with one little modification:

import {Pipe, PipeTransform} from '@angular/core';
import {TimeAgoPipe} from 'time-ago-pipe';

@Pipe({
  name: 'timeAgo',
  pure: false
})
export class TimeAgoExtendsPipePipe extends TimeAgoPipe implements PipeTransform {

  transform(value: string): string {
    return super.transform(value);
  }
}

Note that you have to implement PipeTransform in order to not get compilation error on @Pipe. Not sure why I both have to extend a class which implements an interface AND implement the interface. But this TimeAgo has caused me enough troubles now, so I'm happy enough as long as it is working.

Hi! the code looks fine, but I still got errors upon compilation :(

EDIT: I got it just by converting my date to string :/

vatsac commented 4 years ago

It does work in Angular 9 with one little modification:

import {Pipe, PipeTransform} from '@angular/core';
import {TimeAgoPipe} from 'time-ago-pipe';

@Pipe({
  name: 'timeAgo',
  pure: false
})
export class TimeAgoExtendsPipePipe extends TimeAgoPipe implements PipeTransform {

  transform(value: string): string {
    return super.transform(value);
  }
}

Note that you have to implement PipeTransform in order to not get compilation error on @Pipe. Not sure why I both have to extend a class which implements an interface AND implement the interface. But this TimeAgo has caused me enough troubles now, so I'm happy enough as long as it is working.

Hi! the code looks fine, but I still got errors upon compilation :(

EDIT: I got it just by converting my date to string :/

please tell me how to convert date to string

madmacc commented 3 years ago

I'm getting this with Angular 10 (in Ionic). The fixes above (including @larsnedb's one ) don't help me.

Fine until I run a prod build. If I run ionic build --prod I get the error:

ERROR in node_modules/time-ago-pipe/time-ago.pipe.d.ts:3:22 - error NG6002: Appears in the NgModule.imports of PipesModule, but could not be resolved to an NgModule class.

This likely means that the library (time-ago-pipe) which declares TimeAgoPipe has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy.

EDIT: I ended up switching to ngx-pipes as it has a timeAgo

sohaiebCollabCp commented 2 years ago

@Fomin2402 Hello, can you please share with us which is the error you got ? to know if this issue concerns my problem too or not .

thank you in advance

ryandavie commented 1 year ago

Slight modification to allow dates:

import { Pipe, PipeTransform } from '@angular/core';
import { TimeAgoPipe } from 'time-ago-pipe';

@Pipe({
  name: 'timeAgo'
})
export class TimeagoFixPipe extends TimeAgoPipe implements PipeTransform {

  transform(value: Date | string): string {
    return super.transform(value.toString());
  }
}