简体   繁体   English

如何在angular2中导入socket.io-client?

[英]how do i import socket.io-client in angular2?

I'm trying to import socket.io in angular2. 我正在尝试在angular2中导入socket.io。

I have tried: 我努力了:

import io from  'socket.io-client';

however this is not working 但是这不起作用

I think what you're looking for is 我想你要找的是

import * as io from 'socket.io-client';

This is the equivalent to 这相当于

var io = require('socket.io-client');

in node. 在节点中。

However since this is running in the browser you will need to use a module loader of some sort to patch the references together. 但是,由于这是在浏览器中运行的,因此您将需要使用某种类型的模块加载器来将引用修补在一起。 Typescript will compile happy, but browser will throw runtime errors if you don't configure the module loader correctly. Typescript会编译愉快,但是如果您没有正确配置模块加载器,浏览器将抛出运行时错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM