在socket.io-client中调用IO时出错,角度为8 [英] Getting error while calling IO in socket.io-client, angular 8
本文介绍了在socket.io-client中调用IO时出错,角度为8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在如下所示的角度项目中调用socket.io-client的IO:
I am calling IO of socket.io-client in my angular project like below:
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/internal/Observable';
import * as io from 'socket.io-client';
@Injectable({
providedIn: 'root'
})
export class SocketclientService {
socket:any;
url:any="ws://localhost:8080"
constructor() {
this.socket = io(this.url);
}
listen(eventname:any,data:any){
return new Observable((subscriber)=>{
this.socket.on(eventname,(data:any)=>{
subscriber.next(data);
})
})
}
emit(eventname:string,data:any){
this.socket.emit(eventname,data);
}
}
但是我总是收到类似这样的错误:
But I am always getting an error like:
Error: src/app/services/socketclient.service.ts:11:19 - error TS2349: This expression is not callable.
Type 'typeof import("C:/somepathtoproject/node_modules/socket.io-client/build/index")' has no call signatures.
11 this.socket = io(this.url);
~~
即使我已经安装了@ types/socket.io-client
I am not getting it why this is showing, even I have installed @types/socket.io-client
推荐答案
在角度10中效果很好:
In angular 10 works fine:
import {io} from 'socket.io-client';
这是官方文档 https://socket.io/docs/v3/client-api/index.html
这篇关于在socket.io-client中调用IO时出错,角度为8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文