Last active
July 3, 2018 23:49
-
-
Save retrospectacus/0a17a7d8fd81861a21f7a72e13163fe1 to your computer and use it in GitHub Desktop.
This file contains 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 {Injectable, Inject} from "@angular/core"; | |
import {Http} from "@angular/http"; | |
import {Observable, BehaviorSubject} from "rxjs"; | |
@Injectable() | |
export class ThisDataService { | |
private thisData: BehaviorSubject<any[]> = new BehaviorSubject([]); | |
public thisDataObs$: Observable<any[]> = this.thisData.asObservable(); | |
constructor ( | |
private http: Http | |
) { | |
this.reloadThisData(); // if you want? | |
} | |
public reloadThisData() { | |
this.http.get("this/data") | |
.subscribe(d => this.thisData.next(d.json())) | |
} | |
public appendSomething(x: any) { | |
this.thisData.next(this.thisData.value.concat(x)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment