1

I was trying to use the ngx-socket-io package, which does not work in Angular.js. Is there an alternative package I can use that will work in Angular?

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 })

    }
}

1 Answer 1

2

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 })
}
Sign up to request clarification or add additional context in comments.

2 Comments

Yes @jayesh You are Right socket.io-client is workign thank you for help me.
it's my pleasure

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.