@NgModule({
...
imports: [
...
NgxCommunicateModule.forRoot()
],
...
})
export class AppModule { }
this.communicate.broadcast("server:start", "Server Started");
this.communicate.on("server:start", (data: any) => {
console.log(data);
});
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() {
this.communicate.broadcast("server:start", "Server Started");
this.communicate.on("server:start", (data: any) => {
console.log(data);
});
}
}