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

后端 未结 7 1621
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:55

    To return a resolved promise, you can use:

    return $q.defer().resolve();
    

    If you need to resolve something or return data:

    return $q.defer().resolve(function(){
    
        var data;
        return data;
    
    });
    
    0 讨论(0)
提交回复
热议问题