Ad

Ngx-socket-io Package Is Not Work In Angular JS

I was try use ngx-socket-io iPackage s not work in anguler JS

https://www.npmjs.com/package/ngx-socket-io Example But Not work.

let know any one if any other package to use in 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 })

    }
}
Ad

Answer

Do you Try socket client angular package ?

it so easy to use and worked in angular js.

Install first 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 })
}
Ad
source: stackoverflow.com
Ad