简体   繁体   中英

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

I'm trying to import socket.io in angular2.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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