ngCordova watch Promise arguments

For the ngCordova documentations and examples for watchAcceleration and watchHeading, the arguments for the Promise look strange. More specifically, I am referring to the order of the arguments in the examples.

I think the typical convention for the Promise then method is (successCallback, errorCallback).

But the example given is (null, errorCallback, successCallback):

var watch = $cordovaDeviceOrientation.watchHeading(options).then(
null, // What’s the null doing here?
function(error) { // error callback before the success callback?
// An error occurred
function(result) { // success callback after error callback?
var magneticHeading = result.magneticHeading;
var trueHeading = result.trueHeading;
var accuracy = result.headingAccuracy;
var timeStamp = result.timestamp;

Did we unknowingly jumbled up the examples previously?

I think it have some logic…

The null function is the success callback, that is null because you are periodically watch the compass
The error call is after the success function as always
And the third function is the notify function of all promises, it makes sense that is this function where you handle your logic because you are monitoring periodically the compass.

Every promise handle by then is always:


You can learn more visiting the angular API page for $q, search for The Deferred API section