AngularJS Scopes and Deferreds
问题 I have a service that does something hard and returns a promise: .factory('myService', function($q) { return { doSomethingHard: function() { var deferred = $q.defer(); setTimeout(function() { deferred.resolve("I'm done!"); }, 1000); return deferred.promise; } }; }) I have a controller that adds a function to the scope using that service: .controller('MyCtrl', function($scope, myService) { $scope.doSomething = function() { var promise = myService.doSomethingHard(); promise.then(function(result