title: Phonegap / Cordova function in Angular factory
body: <p>I'm trying to wrap the PushPlugin in a Angular factory, based on <a href="http://devgirl.org/2013/06/10/quick-start-guide-phonegap-and-angularjs/" rel="nofollow">devgirls post</a>, but so far without success.</p>
  
  <pre><code>angular.module('phonegap', [])
    .factory('phonegapReady', function ($rootScope, $q) {
      var loadingDeferred = $q.defer();
  
      document.addEventListener('deviceready', function () {
        $rootScope.$apply(loadingDeferred.resolve);
      });
  
      return function phonegapReady() {
        return loadingDeferred.promise;
      };
    })
    .factory('push', function ($rootScope, phonegapReady) {
      return {
        registerPush: phonegapReady().then(function (onSuccess, onError) {    
  
          // stripped handlers
  
          if (device.platform === 'android' || device.platform === 'Android') {
            pushNotification.register(
              function () {
                var that = this,
                  args = arguments;
  
                if (onSuccess) {
                  $rootScope.$apply(function () {
                    onSuccess.apply(that, args);
                  });
                }
              },
              function () {
                var that = this,
                  args = {
                    'senderID': '123',
                    'ecb': 'onNotificationGCM'
                  };
  
                if (onError) {
                  $rootScope.$apply(function () {
                    onError.apply(that, args);
                  });
                }
              }
            );
          } else {
            pushNotification.register(
              function () {
                var that = this,
                  args = arguments;
  
                if (onSuccess) {
                  $rootScope.$apply(function () {
                    onSuccess.apply(that, args);
                  });
                }
              },
              function () {
                var that = this,
                  args = {
                    'badge': 'true',
                    'sound': 'true',
                    'alert': 'true',
                    'ecb': 'onNotificationAPN'
                  };
  
                if (onError) {
                  $rootScope.$apply(function () {
                    onError.apply(that, args);
                  });
                }
              }
            );
          }
        })
      };
    });
  </code></pre>
  
  <p>Getting an error:</p>
  
  <pre><code>TypeError: '[object Object]' is not a function (evaluating 'e.registerPush(function(a){console.log("fun"),console.log(a)})')
  </code></pre>
  
  <p>What am I doing wrong?</p>