angular-deferred-bootstrap icon indicating copy to clipboard operation
angular-deferred-bootstrap copied to clipboard

injecting service to 'onError'

Open tifidy opened this issue 10 years ago • 3 comments

How can I inject anything to the

onError: function (response, localStorageService) { 
//delete token from storage
})

this is exactly what I need to do with my app but cant inject!

tifidy avatar Jul 03 '15 06:07 tifidy

+1

kmhigashioka avatar May 19 '16 03:05 kmhigashioka

+1

metekabak avatar Sep 20 '16 11:09 metekabak

I think you can add an else if to the handleError function:

function handleError(error) {
    addErrorClass();
    if (isFunction(config.onError)) {
        config.onError(error);
    } else if (isArray(config.onError)) {
        promises = [];
        callResolveFn(config.onError, 'handleError');
        $q.all(promises).then(handleResults, handleError);
    }
}

Then, it may be possible to use:

onError: ['localStorageService', function (response, localStorageService) { 
    //delete token from storage
})

But be aware that it can perform an endless loop in your page if the error is being caused by localStorageService.

washington-guedes avatar Oct 27 '16 15:10 washington-guedes