moribvndvs / ng2-idle

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

Error: No provider for KeepaliveSvc! at NoProviderError.BaseError #24

Closed duderdice closed 7 years ago

duderdice commented 7 years ago

When using the "ng2-idle" component without the "ng2-idle-keepalive", the sample documentation on how to use causes me to get the following error when using Angular2 (currently using 2.1.x):

Error: No provider for KeepaliveSvc! at NoProviderError.BaseError [as constructor]

However, I can get around this but doing both of the following...

@NgModule({
    providers: [
        IDLE_PROVIDERS, {provide: KeepaliveSvc, useValue: undefined}, <-- insert a fake KeepaliveSvc injectable
    ],

and

export class AppComponent {
    private configureIdleBehavior() {
        // this._idle.setKeepaliveEnabled(false); //must comment this out, else app wants a valid KeepaliveSvc

My fix was pieced together with the help of some other issues but wanted to report it here so the documentation on the main page can be updated accordingly to help others getting bitten by this, or to actually fix the providers in the component to work properly with the official Angular 2+ releases.

duderdice commented 7 years ago

Wow, thanks for the quick turn around!

duderdice commented 7 years ago

When using the new NgModule approach as follows,

import { Ng2IdleModule } from 'ng2-idle';

@NgModule({
    imports: [
        ....
        Ng2IdleModule.forRoot(),
    ]

I get the following error:

Unexpected value '[object Object]' imported by the module 'AppModule'

is there more to the story? or perhaps a fix needed against this commit for using NgModule approach?