grbsk / ng2-idle

Responding to idle users in Angular (not AngularJS) applications.
https://grbsk.github.io/ng2-idle
Apache License 2.0
324 stars 129 forks source link

feat(core & keepalive): [On behalf of Planally Sdn Bhd]: Angular 17 migration #200

Closed msibhuiyan closed 4 months ago

msibhuiyan commented 4 months ago

Please check if the PR fulfills these requirements

What kind of change does this PR introduce? (check one with "x")

[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[X] Other : Update deps version

What is the current behavior? (You can also link to an open issue here)

What is the new behavior?

Does this PR introduce a breaking change? (check one with "x")

[X] Yes
[ ] No

If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...

Other information: Although this PR helped us to use with standalone component, but the old NgModule approach is still available to use.

coveralls commented 4 months ago

Coverage Status

coverage: 100.0%. remained the same when pulling ec8d0ce551a47580cf84dc842bf030e542140ceb on planally:angular-17-migration into 08ce89e2a3deeb12811b1d1142ceb902bcb80fee on moribvndvs:master.

grbsk commented 4 months ago

Thanks @BhuiyanSaif18 for this PR.

HarelM commented 2 months ago

Any chance for a migration guide from how it used to work with Module vs how to use it now? I've having a hard time understanding this change...

msibhuiyan commented 2 months ago

Any chance for a migration guide from how it used to work with Module vs how to use it now? I've having a hard time understanding this change...

Hi @HarelM, This PR added support for new service registration approach in ApplicationConfig. Previously we used to configure our NgModule like this

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    NgIdleKeepaliveModule.forRoot() // use NgIdleModule.forRoot() if not using keepalive
   // We registered the NgIdle modules here.
  ],
  providers: [],
  bootstrap: [AppComponent]
})

Now in the new ApplicationConfig approach we register the NgIdle services like this & remove the NgIdleKeepaliveModule.forRoot() from NgModules.

export const appConfig: ApplicationConfig = {
  providers: [
    provideZoneChangeDetection({ eventCoalescing: true }),
    provideRouter(routes),
    provideNgIdleKeepalive(), // use provideNgIdle() if not using keepalive
   // We are registering NgIdle services here
    provideHttpClient(withFetch())
  ]
};

Now this ApplicationConfig allows us to register the service at root level, we can move service registration to component level with provideNgIdleKeepalive(), provideNgIdle() by using the providers array of component or route.

Please do let me know if you need more clarifications.

HarelM commented 1 month ago

Thanks for the info! This was very helpful.