An open API service indexing awesome lists of open source software.

https://github.com/khalidsheet/ngx-communicate

Share data between any two components in an easy way!
https://github.com/khalidsheet/ngx-communicate

angular communicate communication ngx

Last synced: 21 days ago
JSON representation

Share data between any two components in an easy way!

Awesome Lists containing this project

README

          

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/0eb77784475f4ed1824fdda9ef00a0f6)](https://www.codacy.com/manual/prog98rammer/ngx-communicate?utm_source=github.com&utm_medium=referral&utm_content=prog98rammer/ngx-communicate&utm_campaign=Badge_Grade) [![npm version](https://badge.fury.io/js/ngx-communicate.svg)](https://badge.fury.io/js/ngx-communicate)

# NgxCommunicate

**Share data between any two components in an easy way**

## Installation

```bash
npm i ngx-communicate
```

## Add the **NgxCommunicateModule** to your **AppModule**

```ts
@NgModule({
...
imports: [
...
NgxCommunicateModule.forRoot()
],
...
})
export class AppModule { }
```

## Use the Service

**To broadcast data**

```ts
this.communicate.broadcast("server:start", "Server Started");
```

**To receive data**

```ts
this.communicate.on("server:start", (data: any) => {
console.log(data);
});
```

---

## Example

```ts
import { NgxCommunicateService } from "ngx-communicate";

@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent implements OnInit {
constructor(private communicate: NgxCommunicateService) {}

ngOnInit() {
// Broadcasting a new event with it's data
this.communicate.broadcast("server:start", "Server Started");

// Receive the data for that event.
// Note: It can be used inside any other component.
this.communicate.on("server:start", (data: any) => {
console.log(data);
});
}
}
```

### License

MIT