user11868862
user11868862

Reputation:

Ngx-socket-io Package is not work in Angular.js

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

    }
}

Upvotes: 1

Views: 2005

Answers (1)

Jalodara Jayesh
Jalodara Jayesh

Reputation: 327

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

Upvotes: 2

Related Questions