I'm new in angular 2 and there is the possibility that I did not understand the power of the observable. I created a simple service that provides REST call using rxjs :
import {Injectable} from '@angular/core';
import {Http, Response, Headers} from '@angular/http';
import {Observable} from 'rxjs/Rx';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
@Injectable()
export class DataService {
constructor(private http: Http) { }
postFoo(){
this.http.get('http://localhost:8080/Sample')
.map(res=>res.json())
.subscribe(
res=>console.log(res)
);
}
}
and I called this method in my component in this way:
ngOnInit(){
this._dataService.postFoo();
}
All this work fine. Now I want to find a way in which every time there is a change in the data, the component re-calls this method. I read something about .distinctUntilChanged
an observable method but I don't know if this is a good way.
I'm sorry if the question is not good or if I did not explain well my problem.
Regards