【问题标题】:ngx-socket-io Package is not work in angular JSngx-socket-io 包在 Angular JS 中不起作用
【发布时间】:2019-12-10 00:30:19
【问题描述】:

我尝试使用 ngx-socket-io iPackage s 在 anguler JS 中不起作用

https://www.npmjs.com/package/ngx-socket-io 示例但不起作用。

如果有其他要在 Angular js 中使用的包,请告诉任何人。

npm install ngx-socket-io


Moddule.js 

import { SocketIoModule, SocketIoConfig } from 'ngx-socket-io';

const config: SocketIoConfig = { url: 'http://localhost:8988', options: {} };

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    SocketIoModule.forRoot(config)
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

ChatService.js

import { Injectable } from '@angular/core
import { Socket } from 'ngx-socket-io'

@Injectable()
export class ChatService {

    constructor(private socket: Socket) { }

    assign_biker(biker_id){

     this.socket.emit("assign_biker_order",{'biker_id:biker_id })

    }
}

【问题讨论】:

    标签: node.js angularjs sockets websocket socket.io


    【解决方案1】:

    你尝试使用套接字客户端角度包吗?

    它很容易使用并且在 Angular js 中工作。

    首先安装socket.io-client。

      npm i socket.io-client
    
     import * as io from 'socket.io-client';
    
     private socket;
    
    constructor() { 
      this.socket = io('here is your socket url');
    }
    
    
    assign_biker(biker_id){
     this.socket.emit("assign_biker_order",{'biker_id:biker_id })
    }
    

    【讨论】:

    • 是的@jayesh你是对的socket.io-client是workign谢谢你的帮助。
    • 这是我的荣幸
    猜你喜欢
    • 1970-01-01
    • 2016-03-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-17
    • 2016-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多