moribvndvs / ng2-idle

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

not AoT compatible? (no exported member 'IDLE_PROVIDERS') #22

Closed sublime392 closed 7 years ago

sublime392 commented 7 years ago

Hi this works fine in dev mode and regular peoduction mode but AoT does not compile. It gives node_modules/ng2-idle/core"' has no exported member 'IDLE_PROVIDERS'. and node_modules/ng2-idle-keepalive/core"' has no exported member 'KEEPALIVE_PROVIDERS'

This is with angular 2.1.0

sublime392 commented 7 years ago

I got it working following an answer in another issue here. I made an idle.hack.ts file with

import { Injectable } from '@angular/core';
import { Idle, SimpleExpiry } from 'ng2-idle/core';

@Injectable()
export class PalIdle extends Idle {
    constructor(expiry: SimpleExpiry) {
        super(expiry, undefined);
    }
}

and then in my app.module

import { SimpleExpiry, IdleExpiry } from 'ng2-idle/core';
import { PalIdle } from './idle.hack';
...
providers: [
    PalIdle,
    SimpleExpiry,
    { provide: IdleExpiry, useExisting: SimpleExpiry },
  ],
...

and finally injecting the new class where needed

constructor(
    private idle: PalIdle,
  ) {}
spicywhitefish commented 7 years ago

I also had difficulty with the "Optional" Keepalive provider.

export const ALL_IDLE_PROVIDERS = [
    LocalExpiry,
    {provide: IdleExpiry, useExisting: LocalExpiry},
    // The following hack is required to avoid DI errors
    {provide: KeepaliveSvc, useValue: undefined},
    Idle
];

Maybe the JS in the current release is compiled incorrectly?

mdsauer commented 7 years ago

I am having the same issue but the fix above is not working for me. I am getting 'SimpleExpiry' is not exported by node_modules\ng2-idle\core.js (imported by app\app.module.js)' I should mention that I am getting this error while executing rollup so I am facing this issue at another point in my build process.

Tiuser4567 commented 7 years ago

@mdsauer can you try import { SimpleExpiry } from 'ng2-idle/simpleexpiry';

mdsauer commented 7 years ago

@Tiuser4567 That worked! I changed my idle.hack.ts to:

    import { Injectable } from '@angular/core';
    import { Idle } from 'ng2-idle/idle';
    import { SimpleExpiry } from 'ng2-idle/simpleexpiry';
    @Injectable()
    export class PalIdle extends Idle {
        constructor(expiry: SimpleExpiry) {
          super(expiry, undefined);
        }
    }

I made similar changes to my app.module.ts:

import { SimpleExpiry } from 'ng2-idle/simpleexpiry';
import { IdleExpiry } from 'ng2-idle/idleexpiry';

I then also added ng2-idle to the commonjs rollup plugin:

        include: [
          'node_modules/rxjs/**',
          'node_modules/angular-in-memory-web-api/**',
          'node_modules/ng2-idle/**'
          ],

Thanks for the help!

mdsauer commented 7 years ago

@dasis You are able to do the AOT compile? I am still getting Error: Error at .../aot/app/app.module.ngfactory.ts:72:32: Module '".../node_modules/ng2-idle/core"' has no exported member 'IDLE_PROVIDERS'. Are you doing anything special regarding ng2-idle in you systemjs.config.js or anywhere else?

TheSniper102 commented 7 years ago

@dasis can you answer that question

http://www.codeproject.com/Questions/1148292/Angular-idel-user-state