Last active
March 19, 2016 08:53
-
-
Save jamesmorgan/75a8e6c08208efcf4b9c 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
export class CompetitionsService { | |
// Create a Subect to observe | |
private _competitionsSource:Subject<Competition[]> = new Subject<Competition[]>(); | |
// Publicly expose the Observable - called share() to allow multiple observers | |
competitionsChanged$:Observable<Competition[]> = this._competitionsSource.asObservable().share(); | |
constructor(private _http:Http) { | |
_http.get('http://localhost:8080/competitions') | |
.map(res => res.json()) | |
.subscribe( | |
data => { | |
// Call next() on on your source to propagrate to observers | |
this._competitionsSource.next(data) | |
}, | |
err => console.error('Failed to load competitions', err), | |
() => console.log('Loaded competitions') | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment