Last active
May 10, 2020 10:57
-
-
Save anmolio/8078d6e9d029be191935df9d9ffdee40 to your computer and use it in GitHub Desktop.
ComponentTwo : 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-componenttwo', | |
template: ` | |
The status id - {{status}} | |
<button (click)="changeStatus()">Change Message</button> | |
`, | |
styleUrls: ['./sibling.component.css'] | |
}) | |
export class CompomemtTwoComponent implements OnInit { | |
stauts:string; | |
constructor(private data: SatatusService) { } | |
ngOnInit() { | |
this.data.currentStatus.subscribe(status => this.status = status) | |
} | |
changeStatus() { | |
this.data.changeStatus("ON") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment