I think I have found the answer to my question.
First, one needs to take into account the fact that then()
, to quote the documentation, returns a new promise which is resolved with the return value of the callback.
See below:
then(successCallback, errorCallback, notifyCallback) – regardless of
when the promise was or will be resolved or rejected, then calls one
of the success or error callbacks asynchronously as soon as the result
is available. The callbacks are called with a single argument: the
result or rejection reason. Additionally, the notify callback may be
called zero or more times to provide a progress indication, before the
promise is resolved or rejected.
This method returns a new promise which is resolved or rejected via
the return value of the successCallback, errorCallback (unless that
value is a promise, in which case it is resolved with the value which
is resolved in that promise using promise chaining). It also notifies
via the return value of the notifyCallback method. The promise cannot
be resolved or rejected from the notifyCallback method.
So I assume that the following callback (that does return something explicitly) will just return undefined
itself wrapped into a promise by then()
:
var goToDashboard = function () {
//TODO: use $q here?
$state.go('dashboard');
};
So I do have a promise - thanks to then()
- and I don't need anything else...