Coder Social home page Coder Social logo

Comments (7)

moribvndvs avatar moribvndvs commented on July 21, 2024 1

[email protected] and [email protected] have been upgraded to [email protected]

from ng2-idle.

stephengeorgewest avatar stephengeorgewest commented on July 21, 2024 1

Woot. That seems to work. I assume this issue can be closed. Probably #10 as well.

from ng2-idle.

moribvndvs avatar moribvndvs commented on July 21, 2024

I'm not much of a webpack user at this point. I grabbed the latest Angular2 Webpack Starter and I'm also having difficulties with it. I've tried it in some other bare angular2 or starter projects and it was fine. Do you have a sample project somewhere?

I ran npm install --save ng2-idle ng2-idle-keepalive, went to src/vendors.ts and added

import 'ng2-idle/core';
import 'ng2-idle-keepalive/core';

Then I went to src/main.browser.ts to bootstrap it by importing the necessary providers and adding them to the bootstrap statement:

import {HTTP_PROVIDERS} from 'angular2/http';
import {IDLE_PROVIDERS} from 'ng2-idle/core';
import {KEEPALIVE_PROVIDERS} from 'ng2-idle-keepalive/core';
return bootstrap(App, [
    ...ENV_PROVIDERS,
    ...PROVIDERS,
    ...DIRECTIVES,
    ...PIPES,
    ...APP_PROVIDERS,
    ...HTTP_PROVIDERS,
    ...IDLE_PROVIDERS,
    ...KEEPALIVE_PROVIDERS
  ])
  .catch(err => console.error(err));

Finally, in src/app/app.component.ts I import Idle and Keepalive to configure and start them. Pretty similar to what I've done for other seeds and examples.

I can't even get passed the original bootstrapping. I get this error when trying to import my providers:

Invalid provider - only instances of Provider and Type are allowed, got: [object Object]
zone.js?e3a6:241 Uncaught TypeError: Cannot read property 'getOptional' of undefined

Of course, trying to step through these pieces is proving to be impossible. So whatever, I just copy the definition of IDLE_PROVIDERS and KEEPALIVE_PROVIDERS right into the bootstrapper and that error goes away, but then I get errors about no provider for Http, which is absolute rubbish.

I need a Webpack adult.

from ng2-idle.

spicywhitefish avatar spicywhitefish commented on July 21, 2024

In my project, based on Angular2 Webpack Starter, I'm able to use ng2-idle (and other 3rd party typescript libraries, like ng2-cookies) without the ... in my bootstrap call, and without explicitly importing anything in vendor.ts. I'm still adding dependencies to vendor.ts, but only for Javascript libraries.

from ng2-idle.

stephengeorgewest avatar stephengeorgewest commented on July 21, 2024

I don't know how @spicywhitefish got it to work, but I couldn't get webpack to play nice. I never got The "Invalid Provider" issue with angular RC6 and "webpack": "^1.13.0", but i am getting the "no provider for Http" bit. I think it is that webpack is keeping ng2-idle-keepalive from finding it, not that it isn't being provided. When I don't include ng2-idle-keepalive, it complains that KeepaliveSvc isn't provided. When I surgically remove that @Optional() keepaliveSvc?: KeepaliveSvc and references bit in node-modules/ng2-idle/src/idle.js, then Idle works fine by itself.

The extra weird bit is that if i simply copy the source into my project, and include it from those folders it works fine. like so:
.
└── src
├── app
│ └── session
│ ├── session.compontent.html
│ ├── session.component.ts
│ ├── session.service.ts
│ ├── ng2-idle
│ │ └── (contents of src )
│ └── ng2-idle-keepalive
│ └── (contents of src )
├── app.component.html
├── app.component.ts
├── main.ts
└── app.module.ts

session.service.ts:
import { Idle, SimpleExpiry, DEFAULT_INTERRUPTSOURCES } from './ng2-idle/core';
import { Keepalive } from './ng2-idle-keepalive/core';

app.module.ts:
import { IDLE_PROVIDERS } from './session/ng2-idle/core';
import { KEEPALIVE_PROVIDERS } from './session/ng2-idle-keepalive/core';

import { SessionComponent } from './session/session.component'
@NgModule({
imports: [
// Modules
HttpModule
],
declarations: [ SessionComponent'],
providers: [
Title,
HttpModule,
KEEPALIVE_PROVIDERS,
IDLE_PROVIDERS,
],
bootstrap: [
// The main app component
AppComponent
]

Note: I did have to update keepalive.ts line 23 to public onPingResponse: EventEmitter<Response> = new EventEmitter<Response>();

from ng2-idle.

smorks avatar smorks commented on July 21, 2024

@stephengeorgewest I have a hunch that the issue you are seeing is related to different versions of Angular. The last released version of ng2-idle (1.0.0-alpha.15) uses angular-2.0.0-rc.5, where as you're trying to use Angular 2 rc6.

You can try using my distribution branches of ng2-idle and ng2-idle-keepalive that use rc6. You'll need something like the following in your package.json file:

    "ng2-idle": "smorks/ng2-idle#v1.0.0-alpha.16-dist",
    "ng2-idle-keepalive": "smorks/ng2-idle-keepalive#v1.0.0-alpha.9-dist"

Those specific versions are for rc6.

Edit: looks like ng-idle 1.0.0-alpha.16 was just released, supporting angular-2.0.0. Try updating your angular version & ng-idle/ng-idle-keepalive, and try again.

from ng2-idle.

stephengeorgewest avatar stephengeorgewest commented on July 21, 2024

Yeah, that seems to work, but (un?)fortunately we updated to 2.0.0 over the weekend.

error TS2345: Argument of type 'Request' is not assignable to parameter of type 'string | Request'.
  Type 'Request' is not assignable to type 'Request'.
    Types have separate declarations of a private property 'contentType'.

I don't see how that should even be an error. RC6 Request and 2.0.0 Request are exactly the same.

from ng2-idle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.