# ngCordova $cordovaPush and Push Notifications

**URL:** <https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565>\
**Category:** uncategorized\
**Created:** [June 12, 2014, 3:40pm UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565 "2014-06-12T15:40:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![arielgpe](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@arielgpe](https://forum.ionicframework.com/u/arielgpe)\
**Post date:** [June 12, 2014, 3:40pm UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565/1 "2014-06-12T15:40:10Z")

</div>

Hey guys, im trying to get the new ngCordova Push notifications to work.

I installed the plugin `cordova plugin add https://github.com/phonegap-build/PushPlugin.git` and added the example code but i keep getting `Unknown provider: $cordovaPushProvider <- $cordovaPush`.

What am i doing wrong?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [June 13, 2014, 2:51am UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565/2 "2014-06-13T02:51:36Z")

</div>

Are you including `ng-cordova.js` before or after `cordova.js`? This is a common issue I’ve seen.

[http://ngcordova.com/docs/](http://ngcordova.com/docs/)

---

<div class="post-metadata">

**Author:** ![arielgpe](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@arielgpe](https://forum.ionicframework.com/u/arielgpe)\
**Post date:** [June 13, 2014, 4:36pm UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565/3 "2014-06-13T16:36:32Z")

</div>

> [@mhartington](#):
>
> [http://ngcordova.com/docs/](http://ngcordova.com/docs/)

Thank you very much, that was my problem. But now im getting `TypeError: Cannot read property 'pushNotification' of undefined` when i try to use the example code in my controller.

---

<div class="post-metadata">

**Author:** ![dharmoslap](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dharmoslap](https://forum.ionicframework.com/u/dharmoslap)\
**Post date:** [July 23, 2014, 1:45pm UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565/4 "2014-07-23T13:45:55Z")

</div>

try to run $cordovaPush after platform is ready

```
controller('MyCtrl', function($scope, $ionicPlatform, $cordovaPush) {
  $ionicPlatform.ready(function() {
  $cordovaPush.register({...});
  });
});

```

that works for me 😊

---

<div class="post-metadata">

**Author:** ![sandy](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sandy/32/7286_2.png) [@sandy](https://forum.ionicframework.com/u/sandy)\
**Post date:** [August 11, 2014, 12:09am UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565/5 "2014-08-11T00:09:06Z")

</div>

What parameters we need to pass in **options** while calling $cordovaPush unregister

```
 $cordovaPush.unregister(options).then(function (result) {
            // Success! 
        }, function (err) {
          // An error occured. Show a message to the user
        });
```

---

<div class="post-metadata">

**Author:** ![ashish](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@ashish](https://forum.ionicframework.com/u/ashish)\
**Post date:** [August 21, 2014, 10:49am UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565/6 "2014-08-21T10:49:20Z")

</div>

how to handle incoming message

---

<div class="post-metadata">

**Author:** ![nvcken](https://avatars.discourse-cdn.com/v4/letter/n/df788c/32.png) [@nvcken](https://forum.ionicframework.com/u/nvcken)\
**Post date:** [August 22, 2014, 7:44am UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565/7 "2014-08-22T07:44:56Z")

</div>

I has try but got `ReferenceError: cordova is not defined` error

---

<div class="post-metadata">

**Author:** ![techntrails](https://avatars.discourse-cdn.com/v4/letter/t/3be4f8/32.png) [@techntrails](https://forum.ionicframework.com/u/techntrails)\
**Post date:** [August 30, 2014, 9:13am UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565/8 "2014-08-30T09:13:55Z")

</div>

I had to wrap $cordovaPush calls in $ionicPlatform.ready() too.

I assume all plugins would be affected?

Shouldn’t ngCordova handle this or at least document it?

---

<div class="post-metadata">

**Author:** ![techntrails](https://avatars.discourse-cdn.com/v4/letter/t/3be4f8/32.png) [@techntrails](https://forum.ionicframework.com/u/techntrails)\
**Post date:** [August 30, 2014, 2:18pm UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565/9 "2014-08-30T14:18:32Z")

</div>

My interpretation of the ngCordova docs was that the callbacks are non-Angular functions. A common Use Case when processing a notification is to change the state/view of the app - ie. $state.go(). To access $state you’ll need to manually inject it outside of Angular (unless somebody can pipe in with a cleaner solution).

```
function onNotificationGCM (event) {
    
    angular.element(document).injector().invoke(function ($state) {
        $state.go('a_specific_chat_window');
      });
}

```

---

<div class="post-metadata">

**Author:** ![dharmoslap](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dharmoslap](https://forum.ionicframework.com/u/dharmoslap)\
**Post date:** [September 4, 2014, 2:29pm UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565/10 "2014-09-04T14:29:40Z")

</div>

True, maybe ngCordova should document it.

---

<div class="post-metadata">

**Author:** ![dharmoslap](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dharmoslap](https://forum.ionicframework.com/u/dharmoslap)\
**Post date:** [September 4, 2014, 2:30pm UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565/11 "2014-09-04T14:30:30Z")

</div>

But you have to try it on device, it won’t work in browser.

---

<div class="post-metadata">

**Author:** ![biapar](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/biapar/32/64378_2.png) [@biapar](https://forum.ionicframework.com/u/biapar)\
**Post date:** [October 15, 2014, 7:23pm UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565/12 "2014-10-15T19:23:50Z")

</div>

HI,

Is’t work for Win8 and WinPhone?

---

<div class="post-metadata">

**Author:** ![sara](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sara/32/68132_2.png) [@sara](https://forum.ionicframework.com/u/sara)\
**Post date:** [November 25, 2014, 6:40pm UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565/13 "2014-11-25T18:40:58Z")

</div>

Hi,  
I’m having the same problem arielgpe had in the first place. I keep getting this error `Unknown provider: pushProvider <- push`. I’ve tried including ng-cordova.js before and after cordova.js and it’s still failing.

Here’s my code:

```
angular.module('diaadia.pushService', [])
.factory('PushProcessingService', ['$http', function($http) {
        function onDeviceReady() {
            var pushNotification = window.plugins.pushNotification;
            pushNotification.register(gcmSuccessHandler, gcmErrorHandler, {
                "senderID": "mySenderID",
                "ecb": "onNotificationGCM"
            });
        }
        function gcmSuccessHandler(result) {
            console.info('NOTIFY pushNotification.register succeeded. Result = '+result)
        }
        function gcmErrorHandler(error) {
            console.error('NOTIFY '+error);
        }
        return {
            initialize : function () {
                document.addEventListener('deviceready', onDeviceReady, false);
            },
            registerID : function (id) {
                var feedURL = 'myURL';
                var successCallback = function(data, status, headers, config) {
                    console.log(data);
                };
                var errorCallback = function(data, status, headers, config, statusText){
                    console.log(data);
                }
                return $http.post(feedURL, {'notification_id': id}).success(successCallback).error(errorCallback);
            }, 
        }
    }]);
 
    function onNotificationGCM(e) {
        switch( e.event )
        {
            case 'registered':
                if ( e.regid.length > 0 )
                {
                    //console.log('REGISTERED with GCM Server -&gt; REGID:' + e.regid + "");
                    var elem = angular.element(document.querySelector('[ng-app]'));
                    var injector = elem.injector();
                    var pushService = injector.get('PushProcessingService');
                    pushService.registerID(e.regid);
                }
                break;
            case 'message':
                break;
            case 'error':
                break;
            default:
                break;
        }
    }

```

I’m able to register the ID in the database so the code apparently it’s working but I don’t understand why I’m having this error…any idea?

Thanks!

---

<div class="post-metadata">

**Author:** ![biapar](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/biapar/32/64378_2.png) [@biapar](https://forum.ionicframework.com/u/biapar)\
**Post date:** [December 29, 2014, 1:59pm UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565/14 "2014-12-29T13:59:42Z")

</div>

Hi, Ionic  
I think that we need more docs on ngCordova Push plugin. Could you create a tutorial?

---

<div class="post-metadata">

**Author:** ![yoavk](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/yoavk/32/75241_2.png) [@yoavk](https://forum.ionicframework.com/u/yoavk)\
**Post date:** [January 13, 2015, 2:26pm UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565/15 "2015-01-13T14:26:39Z")

</div>

I had this problem, in the end I solved it by adding ‘ **ngCordova** ’ to the ‘starter’ module dependency

```
    angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'ionic.utils', 'ngCordova'])

  .run(function ($ionicPlatform, $localstorage, $cordovaPush) {
    $ionicPlatform.ready(function () {

...
```

---

<div class="post-metadata">

**Author:** ![amolv](https://avatars.discourse-cdn.com/v4/letter/a/cc9497/32.png) [@amolv](https://forum.ionicframework.com/u/amolv)\
**Post date:** [January 28, 2015, 9:23am UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565/16 "2015-01-28T09:23:31Z")

</div>

calling $cordovaPush.register in a controller doesnt call back ecb, any luck anyone?

---

<div class="post-metadata">

**Author:** ![prabhu\_108](https://avatars.discourse-cdn.com/v4/letter/p/b5a626/32.png) [@prabhu\_108](https://forum.ionicframework.com/u/prabhu_108)\
**Post date:** [January 28, 2015, 10:54pm UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565/17 "2015-01-28T22:54:12Z")

</div>

Same issue here. After calling regiser(), I don’t get a call back with the registration id.

---

<div class="post-metadata">

**Author:** ![darrenahunter](https://avatars.discourse-cdn.com/v4/letter/d/ecb155/32.png) [@darrenahunter](https://forum.ionicframework.com/u/darrenahunter)\
**Post date:** [January 28, 2015, 11:12pm UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565/18 "2015-01-28T23:12:53Z")

</div>

are you running on a actual device or in simulator or browser

my experience is it needs to be on the actual device to work

---

<div class="post-metadata">

**Author:** ![prabhu\_108](https://avatars.discourse-cdn.com/v4/letter/p/b5a626/32.png) [@prabhu\_108](https://forum.ionicframework.com/u/prabhu_108)\
**Post date:** [January 28, 2015, 11:29pm UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565/19 "2015-01-28T23:29:25Z")

</div>

Actual device. I’m on a Nexus 5. I actually posted an issue about this with sample code, but I can’t find the post. Not sure if the team removed it for whatever reason.

I have it posted on stackoverflow as well:

> <https://stackoverflow.com/questions/28202565/can-t-get-push-notifications-in-android-to-work-using-ngcordova>

---

<div class="post-metadata">

**Author:** ![darrenahunter](https://avatars.discourse-cdn.com/v4/letter/d/ecb155/32.png) [@darrenahunter](https://forum.ionicframework.com/u/darrenahunter)\
**Post date:** [January 28, 2015, 11:44pm UTC](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565/20 "2015-01-28T23:44:39Z")

</div>

you should be able to put ‘alerts’ in the ngcordova source and see if the events are being posted

[Next page](https://forum.ionicframework.com/t/ngcordova-cordovapush-and-push-notifications/5565.md?page=2)
