First of all, the service is well executed, as you did, and this is the way to go with Angular2: A Class introduced in other components.
However, about the other issues you are raising, I would rather go back and keep the result in a promise instead of using a callback:
getAll() { return players || players = new Promise( (resolve) => this.http.get('people.json').observer({next: resolve}) ); }
Note You can use Observable.toPromise (), but for some reason it doesn't work for me in Angular2
Thus, further calls to getAll () will not trigger more responses.
For synchronous questions you should not do this. Now that you have this in the promise, just call getAll () and return the promise when the player requests.
get(id) { return getAll().then((result) => {return Promise.resolve(result[id])}); }
About how to handle additions and deletions of players, exactly what Observables is for RxJS. You also need to provide an observable stream that notifies it of observers when changing the list of players. You can use EventEmitter to do this:
constructor( @Inject(Http) http) { this.http = http; this.myEventEmitter = new EventEmitter(); } getUpdateStream() { myEventEmitter.toRx(); }
When you change the list of players, just myEventEmitter.next(players)
Alfonso presa
source share