I am trying to evaluate Angular 2 and I am having problems with observables.
I am trying to create a simple service that initially returns a hard coded array but wil
For this you can user BehaviorSubject
export class FleetListService {
public data: any = new BehaviorSubject('your hard coded data goes here');
getdata() {
//do your stuff
this.FleetListService.next('new data got from server');
}
}
One of the variants of Subjects is the BehaviorSubject, which has a notion of "the current value". It stores the latest value emitted to its consumers, and whenever a new Observer subscribes, it will immediately receive the "current value" from the BehaviorSubject. Behaviour subject always returns last data. For more info