Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度工厂中的Phonegap/Cordova函数_Angularjs_Cordova_Phonegap Plugins - Fatal编程技术网

Angularjs 角度工厂中的Phonegap/Cordova函数

Angularjs 角度工厂中的Phonegap/Cordova函数,angularjs,cordova,phonegap-plugins,Angularjs,Cordova,Phonegap Plugins,我正试图将PushPlugin包装在一个基于的角度工厂中,但迄今为止没有成功 angular.module('phonegap', []) .factory('phonegapReady', function ($rootScope, $q) { var loadingDeferred = $q.defer(); document.addEventListener('deviceready', function () { $rootScope.$apply(lo

我正试图将PushPlugin包装在一个基于的角度工厂中,但迄今为止没有成功

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);
                });
              }
            }
          );
        }
      })
    };
  });
获取错误:

TypeError: '[object Object]' is not a function (evaluating 'e.registerPush(function(a){console.log("fun"),console.log(a)})')

我做错了什么?

当你调用
然后
承诺时,它会返回承诺,这样你就可以链接回调

我认为用函数包装
registerPush
是可行的,比如:

registerPush: function(onSuccess, onError) {
    phonegapReady().then(function () {   
        // Do something with closured onSuccess and onError
    });
},..