LocalNotifications.on('click') go to url setRoot


I would like to load a specific page when I click on a LocalNotification :

LocalNotifications.on(‘click’, (notification) => {

It’s working if I put that code on the current page open in the app. But if I’m on another page is not working obviously. So where I should put that code? Because, apparently I cannot use NavController in app.component or main.ts.

Thank you very much for your help !

you can use the broadcast event
if you got the notifiaction just broadcast the event you may use $scope.$emit(‘someEvent’);
listen the event in the controller you want like this
$scope.$on(‘someEvent’, function(event) { });

Thank you for your reply.

I’m on Ionic2. I used Events. And it works. Thank you !

constructor(…, public eventsApi: Events)

in app.component.ts

LocalNotifications.on(‘click’, (notification) => {
events.publish(‘localnotification:click’, notification.data); // see home.ts eventsApi.subscribe

in my home page

events.subscribe(‘localnotification:click’, (data) => {
data = JSON.parse(data);

1 Like