I am using $q
to wrap a promise around a legacy callback. However, the existing callback doesn't have a value to return. It takes a success function with no parameters.
angular.module('MyModule').service('MyService', function() {
function initialize() {
var deferred = $q.defer();
LegacyFactory.initialize(
// 'void' Success Callback
function () {
deferred.resolve (/* WHAT DO I PUT HERE? */);
},
// Error Callback
function (errorCode) {
deferred.reject(errorCode);
});
return deferred.promise;
}
});
I can't find a void
version of resolve
in the AngularJS docs. I can return a dummy value, but then clients might access that dummy value, which would cause confusion.
How do I create an AngularJS promise with no return value?
NOTE: The question AngularJS promise returning empty object is completely different. That question does return a value in the resolve
function.
deferred.resolve()
? – Meingoldasdeferred.resolve()
all the time. – Faliscan