我试图在Angular 2应用中使用Socket.io-client
库。
Angular 2在过去几个月里有很多与快速变化相关的指南。
我不知道我做错了什么。
我做了什么?
npm install socket.io-client --save
之后在组件中:
...
import * as io from "socket.io-client";
...
export class MyComponent implements OnInit {
socket: SocketIOClient.Socket;
constructor() {
this.socket = io.connect("http://localhost:4200");
this.socket.on("connection", () => console.log("this is onl a test"));
}
}
}
当我打开控制台时,我看到以下错误:
GET http://localhost:4200/socket.io/?EIO=3&transport=polling&t=LdBXte5 404 (Not Found)