Skip to content

Commit

Permalink
Included documentation for standalone applications (rodgc#178)
Browse files Browse the repository at this point in the history
* update docs

* tell file
  • Loading branch information
meurele authored Oct 24, 2024
1 parent 3975561 commit 62cd3fb
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Make sure you're using the proper corresponding version of socket.io on the serv

## How to use

### Import and configure SocketIoModule
### Import and configure SocketIoModule for NgModule based applications

```ts
import { SocketIoModule, SocketIoConfig } from 'ngx-socket-io';
Expand All @@ -47,6 +47,25 @@ We need to configure `SocketIoModule` module using the object `config` of type `

Now we pass the configuration to the static method `forRoot` of `SocketIoModule`

### Import and configure SocketIoModule for standalone based applications

In app.config.ts use the following:

```ts
import { ApplicationConfig, importProvidersFrom } from '@angular/core';
import { SocketIoModule, SocketIoConfig } from 'ngx-socket-io';

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

export const appConfig: ApplicationConfig = {
providers: [
importProvidersFrom(SocketIoModule.forRoot(config))
]
};
```

For standalone applications we do not have the AppModule where we can import the `SocketIoModule`. Instead we can use the `importProvidersFrom` provided by angular to provide the `SocketIoModule` to our application. The usage of the socket instance is then the same as if we used a NgModule based application.

### Using your socket Instance

The `SocketIoModule` provides now a configured `Socket` service that can be injected anywhere inside the `AppModule`.
Expand Down

0 comments on commit 62cd3fb

Please sign in to comment.