I want to resolve a promise object the same way it would be done Angular's defer.resolve with the Javascript Promise object. Put another way: I want to create a dummy promise object to be returned. This promise will be resolved later on.
In Angular I would write it this way:
...
$scope.checkThis = { test: false };
function getPromise() {
var deferred = $q.defer();
var data = [1, 2, 3];
function resolvePromise() {
deferred.resolve(data);
}
$scope.$watch("checkThis.test", function(newVal, oldVal) {
if (newVal) {
resolvePromise();
}
});
return deferred.promise;
}
$scope.getData1 = function() {
return getPromise();
};
$scope.getData2 = function() {
return getPromise();
};
...
How would I achieve the same with the plain Javascript Promise object? I don't see how to use the Promise constructor as there is one event ($scope.checkThis.test becoming true) that will trigger several resolve.