Skip to content

Instantly share code, notes, and snippets.

@retrospectacus
Last active July 3, 2018 23:49
Show Gist options
  • Save retrospectacus/0a17a7d8fd81861a21f7a72e13163fe1 to your computer and use it in GitHub Desktop.
Save retrospectacus/0a17a7d8fd81861a21f7a72e13163fe1 to your computer and use it in GitHub Desktop.
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