Change angular state after push reception


I have the following problem :
In my main controller, I have this function that is called when a push arrived on iOS device :

onNotificationAPN = function(event) {
if (event.alert) {
if (event.sound) {
var snd = new Media(event.sound);;
if (event.badge) {
pushNotification.setApplicationIconBadgeNumber(successHandler, errorHandler, event.badge);
// do some work with event

But it can’t work because $state is unknown.

Have you already tried to change the angular state after a push notification?

Thanks for your help

It’s hard to tell from your sample, but I’m assuming that onNotificationAPN is a global function outside of Angular. Generally speaking, Angular doesn’t talk to the outside world. So, you have to resort to a few hacks to get that global function to talk to angular.

Here’s how I do it:

document.addEventListener('push-notification', function(event) {

    var body = document.getElementsByTagName("body")[0];
    var appController = angular.element(body).scope();


Here’s an explanation of how this works :

Also, here’s another post about similar subject : How to integrate Cordova/Phonegap plugins within Angular/Ionic the right way?

The problem was this object beacause it wad undefined


The change of state is now OK