ngCordova $cordovaPush and Push Notifications

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

I installed the plugin cordova plugin add and added the example code but i keep getting Unknown provider: $cordovaPushProvider <- $cordovaPush.

What am i doing wrong?

Thanks in advance.

1 Like

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

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.

try to run $cordovaPush after platform is ready

controller('MyCtrl', function($scope, $ionicPlatform, $cordovaPush) {
  $ionicPlatform.ready(function() {

that works for me :blush:

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

how to handle incoming message

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

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?

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) {

True, maybe ngCordova should document it.

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


Is’t work for Win8 and WinPhone?

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) {
  '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) {
                var errorCallback = function(data, status, headers, config, statusText){
                return $, {'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');
            case 'message':
            case 'error':

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?


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


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

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

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

1 Like

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

1 Like

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

1 Like

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

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:

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