Ng-Idle Throws this error

I am trying to implement ng-idle from this answer : Set the logout time if user is inactive?

My Source code :

  1. New project created. ionic start NgIdleApp blank --type=ionic-angular
  2. Used the command : npm install --save @ng-idle/core
  3. Changed my App.component.ts to this:

import { Component } from ‘@angular/core’;
import { Platform } from ‘ionic-angular’;
import { StatusBar } from ‘@ionic-native/status-bar’;
import { SplashScreen } from ‘@ionic-native/splash-screen’;

import { HomePage } from ‘…/pages/home/home’;
import { Idle, DEFAULT_INTERRUPTSOURCES } from ‘@ng-idle/core’;

@Component({
templateUrl: ‘app.html’
})
export class MyApp {
rootPage:any = HomePage;

constructor(
private idle: Idle,
platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
this.idleManagement();
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
});
}
idleManagement() {
// sets an idle timeout of 5 seconds, for testing purposes.
this.idle.setIdle(10);

// sets a timeout period of 5 seconds. after 10 seconds of inactivity, the user will be considered timed out.
this.idle.setTimeout(10);

// sets the default interrupts, in this case, things like clicks, scrolls, touches to the document
this.idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);

this.idle.onIdleEnd.subscribe(() => { console.log("No longer idle."); });
this.idle.onTimeout.subscribe(() => {
  console.log("Timed out!");
  // this.timedOut = true;
});
this.idle.onIdleStart.subscribe(() => { console.log("You've gone idle!"); });
this.idle.onTimeoutWarning.subscribe((countdown) => {
  console.log("You will time out in " + countdown + " seconds!");
});

}
}

  1. used command : ionic serve
  2. Image output

Error : Object(WEBPACK_IMPORTED_MODULE_0_rxjs[“fromEvent”]) is not a function. (In ‘Object(WEBPACK_IMPORTED_MODULE_0_rxjs[“fromEvent”])(target, eventName, opts)’, ‘Object(WEBPACK_IMPORTED_MODULE_0_rxjs[“fromEvent”])’ is an instance of Object)

Can anyone help me out with this?

@ng22792 any luck figuring this one out? Did you find an alternative to ng-idle? Thanks!

1 Like

@batianusrey I actually figured out the error.
It seems that the latest versions of ng-idle and keepalive wont work with my version of ionic-cli. I had to download these using the commands:

npm install --save @ng-idle/core@2.0.0-beta.10
npm install --save @ng-idle/keepalive@2.0.0-beta.10
npm install --save angular2-moment

Then things started working fine.