Last active
April 6, 2020 07:25
-
-
Save anmolio/5306740625ee49c96da5f42535af8179 to your computer and use it in GitHub Desktop.
ComponentOne : Unrelated Components subscribing to data using a serivce (BehaviorSubject)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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