1
我試圖根據devgirls post在Angular工廠包裝PushPlugin,但目前爲止沒有成功。Angular工廠的Phonegap/Cordova函數
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)})')
我在做什麼錯?