0

I've been working with angular a lot lately and one thing I wanted to do was use a declared function instead of a place that takes the word "function() {}", like in a promise callback for example. I had a few server requests that, on error, all do the same thing, so instead of saying:

.then(function(data) {

}, function(error) {

});

I wanted to do the following:

.then(function(data) {
}, handleError(error));

function handleError(error) { console.log(error); }

but it wasnt working. Did I make a mistake in how I tried to do this or is this just not possible?

1
  • 3
    }, handleError.bind(null, error)); Commented Aug 5, 2015 at 2:18

1 Answer 1

3

When writing handleError(error), you're calling the function (with some error variable as the argument, which probably doesn't even exist). You just want to pass the function:

.then(function(data) {
     …
}, handleError);

No parenthesis!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.