How to refresh current page upon receiving push notification?

Currently, I’m working on push notification integration with my Ionic2 App. It is able to receive the push notification, however I would like to refresh the current page upon notification is received. Let say, I have a tab with badge in current page, once new messages arrived, I’ll increase the badge number programmatically.

The logic to handle the received notification is inside a service, if it is possible to get the current view/component and invoke specific function to refresh the view. e.g. this.navCtrl.getActive().refreshMethod(data). refreshMethod is implemented in component.

plz forgive my poor English, Really appreciate if anyone can give me some advice.

a service should not do anything which triggers changes in the view.

Your service could be provide a Subject --> that calls its next() method, if the page needs to be refreshed --> in the PageComponent you can subscribe the subject --> so every time the service informs, that there should be a page refresh your subscription callback is called.

So you do not need strange dependencies or calls of component functions in services.


@bengtler I suddenly see the light, thank you so much.

1 Like

haha, no probs… let us know if you need some additional hints :wink:

1 Like

I managed to make it works by using rxjs Subject, the code snippets look more elegant without the strange dependency. Thanks again, boss.:grin:

1 Like

hey…I am also having the same issue, could you please share the code snippet. How you are using push notification in the service.