How to return a resolved promise from an AngularJS Service using $q?

后端 未结 7 1654
Happy的楠姐
Happy的楠姐 2020-12-05 17:23

My service is:

myApp.service(\'userService\', [
  \'$http\', \'$q\', \'$rootScope\', \'$location\', function($http, $q, $rootScope, $location) {
    var defe         


        
7条回答
  •  情话喂你
    2020-12-05 17:36

    Return your promise , return deferred.promise.
    It is the promise API that has the 'then' method.

    https://docs.angularjs.org/api/ng/service/$q

    Calling resolve does not return a promise it only signals the promise that the promise is resolved so it can execute the 'then' logic.

    Basic pattern as follows, rinse and repeat
    http://plnkr.co/edit/fJmmEP5xOrEMfLvLWy1h?p=preview

    
    
    
    
      
      
      
    
    
    
    
    

提交回复
热议问题