[英]Using socket.io-client in angular-cli@webpack
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. 我想在我的Angular 2应用程序中使用socket.io,而且我从Angular 2应用程序中获取访问权限并不是很幸运。 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 角度2:rc.5 angular-cli:1.0.0-beta.11-webpack.2节点: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: 我已经通过npm和typings安装了socket.io,我在node_modules目录中看到它,但是Angular 2应用程序似乎无法解决:
import * as io from 'socket.io-client'; 从'socket.io-client'导入*作为io;
I've seen a posts about how to address this using webpack and it's config files, but those don't seem to exist for an application generated with angular-cli@webpack. 我已经看过一篇关于如何使用webpack和它的配置文件解决这个问题的帖子,但是对于使用angular-cli @ webpack生成的应用程序来说,这些文件似乎不存在。
Any suggestions, pointers, etc would be greatly appreciated! 任何建议,指针等将不胜感激!
Thanks! 谢谢! Doug 道格
All you need should be the following: 您所需要的只是以下内容:
npm: 故宫:
npm install socket.io-client --save
import in your component.ts/service.ts 在component.ts / service.ts中导入
import * as io from 'socket.io-client';
a dummy module declaration in your typings.d.ts: 你的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. 我不知道打字是否可用,但您可以尝试使用npm i @types/socket.io-client --save-dev
而不是仅仅声明一个假人。
Any webpack config should be taken care of by angular-cli. 任何webpack配置都应该由angular-cli来处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.