Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular 17 support #69

Open
benshabatnoam opened this issue Jan 30, 2024 · 5 comments
Open

Angular 17 support #69

benshabatnoam opened this issue Jan 30, 2024 · 5 comments

Comments

@benshabatnoam
Copy link

Hi there,
Will you guys be able to update this package to support Angular 17?
Thank!

@bastibense
Copy link

bastibense commented Feb 16, 2024

I'd also be interested in an update.

Trying to implement ngx-timeago with the latest Angular version - and it kinda works.

Even though I'm trying to assign the localized strings in the constructor of my component to the service and call the changes.next() method, the text stays in english.

In the debugger I can see the string values in german being assigned to the service - but it doesn't do anything.

Since Angular 17 has a little different architecture, my approach was to put TimeagoModule.forRoot({}) into
importProvidersFrom in app.config.ts.
Also I added TimeagoIntl to the providers list there.

Some updated docs might be nice, too!

Any hints are welcome!

@CosovanuA
Copy link

Hi! I've encountered the same problem, using standalone components also.
The solution that worked for me:

In main.ts:

...
providers: [
      importProvidersFrom(
        BrowserModule,
        AppRoutingModule,
        TimeagoModule.forRoot({
          intl: {
            provide: TimeagoIntl,
          },
          formatter: {
            provide: TimeagoFormatter,
            useClass: TimeagoCustomFormatter,
          },
        })
      ),
      AuthService,
      ScreenService,
      AppInfoService,
    ]

In app.component.ts:

import { strings as roIntlStrings } from 'ngx-timeago/language-strings/ro';
constructor(
    ...
    private timeagoIntl: TimeagoIntl
  ) {
    this.timeagoIntl.strings = roIntlStrings;
    this.timeagoIntl.changes.next();
  }

@nandyalu
Copy link

I am using standalone components in Angular 17 and I was able to solve this by importing in app.config.ts as below:

import { TimeagoModule } from "ngx-timeago";
import { routes } from './app.routes';
<other imports>

export const appConfig: ApplicationConfig = {
  providers: [
    provideRouter(routes),
    //<other imports as needed>
    importProvidersFrom(
      TimeagoModule.forRoot()
    )
  ]
};

And in component.ts simply import the TimeagoModule and use timeago pipe in your template where needed

@Component({
  standalone: true,
  imports: [CommonModule, TimeagoModule],
  template: `{{ '2023-08-21T14:54:38.342Z' | timeago }}`,
})
export class ExampleComponent { ... }

@augiegardner
Copy link

None of this is working for me -
Upgrading fro 16 to 17 and this module is not working.
Not using standalone components
Tries every solution in here, but not sure what app.config.ts is supposed to be

@ihym
Copy link
Owner

ihym commented Sep 3, 2024

anyone interested to open a PR? 👀

This was referenced Sep 11, 2024
Repository owner deleted a comment from rbalet Sep 11, 2024
Repository owner deleted a comment from rbalet Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants