2014-01-20 2 views
1

정확도가없는 devgirls post을 기반으로하는 Angular 팩토리에서 PushPlugin을 래핑하려고합니다.Phonegap/Cordova 함수가 각도 팩토리

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

내가 잘못 뭐하는 거지 :

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); 
       }); 
       } 
      } 
     ); 
     } 
     }) 
    }; 
    }); 

오류를 얻기?

답변

2

약속에서 then을 호출하면 약속을 반환하므로 콜백을 연결할 수 있습니다.

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

내가 좋아하는 기능을 registerPush 포장 작업 것이라고 생각

관련 문제