I'm working on angular 2 webapp, I navigate to xyz component when I have data in my array and stores it in service component. The xyz component's ngOnInit() method get data from service and displays it to its html template. The problem is that when my source array data changes I'm redirecting to xyz component again but then xyz's ngOnInit() method does not get invoked this time. Is there any way to achieve this ?
Asked
Active
Viewed 159 times
0
-
Why are you routing again... why don't retrieve the the data again after making changes? – AT82 Apr 27 '17 at 11:03
1 Answers
0
You could subscribe to an event in your component. I don't know how to integrate this to you code, but on mine it looks like this :
ngOnInit() {
this._events.xyz.onDataChange.subscribe (() => {
this.onDataChange();
}
onDataChange() {
// Display to HTML Template
}
And then, when your data changes, you use
this._events.xyz.onDataChange().publish()
I'm using a TypeScript class EventsManager, you can probably do this kind of things with angular's events.
You should wait for answers from more experienced developers though.

Antoine Laborderie
- 141
- 10