Consider the following example:
.service('movieGetter', ['$q', '$timeout', function ($q, $timeout) { this.getData = function () { var deferred = $q.defer(); $timeout(function(){ mock.getData(function(data){ deferred.resolve(data); }); }, 2000); return deferred.promise; }; }]);
For some reason, this code does not work when the line offferred.resolve () starts the callback, and then in the constructor does't
On the other hand, this example works just fine:
.service('movieGetter', ['$q', '$timeout', function ($q, $timeout) { this.getData = function () { var deferred = $q.defer(); $timeout(function () { deferred.resolve('test'); }, 2000); return deferred.promise; }; }]);
Determine the reason why the deferred .resolve () function fires inside the callback, then the callback on the constructor does not work.
Any ideas?
Thanks!
source share