From 62cd3fb59702c59ae1b94df0faf365f479e65ac3 Mon Sep 17 00:00:00 2001 From: meurele <94800217+meurele@users.noreply.github.com> Date: Thu, 24 Oct 2024 18:12:24 +0200 Subject: [PATCH] Included documentation for standalone applications (#178) * update docs * tell file --- README.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a099606..79a727d 100644 --- a/README.md +++ b/README.md @@ -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'; @@ -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`.