Use $q.when (or $q.resolve with AngularJS 1.4.1) to create an already resolved promise.
var p = $q.resolve(); if (condition) { p = p.then(doOptionalFirst); } return p.then(doOther);
If you are using deferred, you need to bind to .promise and then allow deferred at the appropriate time. In this case, you can assume that if condition true, deferred is automatically resolved. Thus, you can skip some additional, perhaps incomprehensible code, simply using promises already resolved.
source share