Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alorel/ngx-sails
Angular bindings for communicating with the sails backend
https://github.com/alorel/ngx-sails
angular bindings ngx sails socket-io socket-io-client
Last synced: 3 months ago
JSON representation
Angular bindings for communicating with the sails backend
- Host: GitHub
- URL: https://github.com/alorel/ngx-sails
- Owner: Alorel
- License: mit
- Created: 2019-09-06T08:56:20.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-02-20T19:09:38.000Z (11 months ago)
- Last Synced: 2024-11-01T23:42:27.879Z (3 months ago)
- Topics: angular, bindings, ngx, sails, socket-io, socket-io-client
- Language: TypeScript
- Homepage:
- Size: 3.02 MB
- Stars: 4
- Watchers: 4
- Forks: 2
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Angular bindings for the sails socket client
Used the abandoned [ngx-sails](https://github.com/brandom/ngx-sails) as a base.
## Installation
- `npm install socket.io-client@^2.0.0`
- `npm install @aloreljs/ngx-sails@CHECK_BELOW`:
- Angular 16: ^4.0.0
- 15: ^3.0.0
- 14: ^2.1.0
- 13: ^2.0.0## Configuration
The following injection tokens can be included in your app module to configure the client:
Provide an existing socket.io instance:
```typescript
import {IO_INSTANCE} from '@aloreljs/ngx-sails';@NgModule({
providers: [{
provide: IO_INSTANCE,
useValue: someIoRef
}]
})
export class AppModule {}
```Provide client configuration:
```typescript
import {NGX_SAILS_CONFIG, NgxSailsConfig} from '@aloreljs/ngx-sails';const config: NgxSailsConfig = {
uri: '/foo',
// socket.io options
options: {
},
// default headers
headers: {
}
}@NgModule({
providers: [{
provide: NGX_SAILS_CONFIG,
useValue: config
}]
})
export class AppModule {}
```## Usage
```typescript
import {SailsClient} from '@aloreljs/ngx-sails';@Component({})
export class MyComponent {
public constructor(private readonly sails: SailsClient) {}public listenForEvent(): void {
this.sails.on('eventName').subscribe(response => {});
}
public makeRequest(): void {
this.sails.get('url').subscribe();
this.sails.post('url', {foo: 'bar'}).subscribe(response => {});
}public emitEventWithoutAResponse(): void {
this.sails.emit('eventName', 'arg1', 'arg2');
}public emitEventWithAResponse(): void {
this.sails.emitAndWait('eventName', 'arg1', 'arg2').subscribe(response => {})
}
}
```