请考虑以下示例:
.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; }; }]);
由于某种原因,当代码行deferred.resolve()在constroller中触发回调时,这段代码不起作用
另一方面,这个例子工作正常:
.service('movieGetter',$timeout) { this.getData = function () { var deferred = $q.defer(); $timeout(function () { deferred.resolve('test'); },2000); return deferred.promise; }; }]);
当deferred.resolve()在回调内部触发时,有一些原因,那么在constroller上的回调不起作用.
有任何想法吗?
谢谢!