B Hull
B Hull

Reputation: 3223

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

Upvotes: 2

Views: 1878

Answers (1)

SnareChops
SnareChops

Reputation: 13347

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.

Upvotes: 4

Related Questions