Issue
I'm tying to use socket.io in my Angular 2 application, and I'm not having much luck getting access to it from within my Angular 2 application. Here's some information about my setup:
Angular 2: rc.5
angular-cli: 1.0.0-beta.11-webpack.2
Node: 6.2.2
OS: Linux x64
I've got socket.io installed via npm and typings, and I see it in my node_modules directory, but that Angular 2 application can't seem to resolve:
import * as io from 'socket.io-client';
I've seen a posts about how to address this using Webpack and its config files, but those don't seem to exist for an application generated with angular-cli@webpack.
Solution
All you need should be the following:
npm:
npm install socket.io-client --save
import in your component.ts/service.ts
import * as io from 'socket.io-client';
a dummy module declaration in your typings.d.ts:
declare module 'socket.io-client' {
var e: any;
export = e;
}
I don't know if typings are available, but you can try npm i @types/socket.io-client --save-dev instead of just declaring a dummy.
Any webpack config should be taken care of by angular-cli.
Answered By - j2L4e
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.