I have a service that uses Observable to get data from database. It seems that it gets data only once . I would that it listen when a user adds data to the DB then stream to Angular.
service to get all data
getAllProj(): Observable<NouveauProjet[]> {
return this.http.get<NouveauProjet[]>(
"http://127.0.0.1:8081/api/proj/projets"
);
}
service to add data
addProj(nouveauProjet: NouveauProjet): Observable<any> {
return this.http.post<NouveauProjet[]>(
"http://127.0.0.1:8081/api/proj/projets",
nouveauProjet
);
}
When I use my services I only subscribe to them
getAllProj() {
this.ajoutProj.getAllProj().subscribe(
response => {
console.log("hello"+response);
this.nouveauProjet=response;
},
error => console.log(error)
);
I thought that Observable still listen to server when a new data is added to DB but it's not the case, so How can I transform my observable to a data stream.