Mainly, I'm using angular2 and I have two components, the first one is responsible for displaying the data coming from the server on my page, the second one which is an ngmodal that pops up, is responsible for doing POST and PUT request to save the data.
the problem here is that when I change or add data, it doesn't get displayed automatically in my view.
Does any one know how to make that happens (make component A aware of the changes made by component B) ? thanks.
How I'm fetching data (component A) :
this.service.getData(this.url)
.subscribe(data => {
this.data = data;
console.log(this.data);
},
err => { console.log('__error__') },
() => { console.log('Success') }
);
How I'm posting data (component B):
add(content: string): void {
if (!content) { return; }
this.service.create(content, this.url)}
My service.get Data:
getData(url:string): Observable<Object[]> {
return this.http.get(url)
.map(res => res.json())
.catch(this.handleError);}
My service.create (post example):
create(content: string, url:string): Observable<Object> {
return this.http
.post(url, JSON.stringify({ content: content }), { headers: this.headers})
.map(res => res.json())
.catch(this.handleError);}