NgOnInit is not called when re-routing to the same component - Angular 2

I am working on angular 2 webapp, I go to the xyz component when I have data in my array and save it in the service component. The method of the xyz component ngOnInit () receives data from the service and displays it in its html template. The problem is that when my original array data changes, I redirect the xyz component again, but then this xyz ngOnInit () method will not be called. Is there any way to achieve this?

0
source share
1 answer

You can subscribe to an event in your component. I don’t know how to integrate this code with you, but in my opinion 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()

TypeScript, , angular.

.

0

Source: https://habr.com/ru/post/1691893/


All Articles