Skip to content

Instantly share code, notes, and snippets.

@anmolio
Last active April 6, 2020 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anmolio/5306740625ee49c96da5f42535af8179 to your computer and use it in GitHub Desktop.
Save anmolio/5306740625ee49c96da5f42535af8179 to your computer and use it in GitHub Desktop.
ComponentOne : Unrelated Components subscribing to data using a serivce (BehaviorSubject)
import { Component, OnInit } from '@angular/core';
import { StatusService } from "../status.service";
@Component({
selector: 'app-componentone',
template: `
The status is - {{status}}
`,
styleUrls: ['./sibling.component.css']
})
export class ComponentOne implements OnInit {
status:string;
constructor(private data: StatusService) { }
ngOnInit() {
this.data.currentStatus.subscribe(status => this.status = status)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment