2016-11-19 33 views
0

我寫了一個簡單的工廠調用我的休息endpont,但我想用不同的地址不只一個,但是當我執行query$resource我只在我的控制檯中獲得文本函數登錄。

這是我廠:

angular.module('blogfontApp.services', []).factory('Blog', function ($resource) { 

    return { 
     getAll : function() { 
      return $resource('http://localhost:8080/api/blog'); 
     } 
    } 

}); 

和我的控制器:

angular.module('blogfontApp.controllers', []).controller('BlogListController', 

    function ($scope, Blog) { 

     $scope.bloglist = Blog.getAll.query(); 


     console.log($scope.bloglist); 

    }); 

如何以不同的地址從我廠打電話?

+0

真不明白你問 – charlietfl

回答

1

嘗試下面使用許諾,

iApp.controller('TestController', function($scope, Blog) { 
    Blog.getAll().query().$promise.then(function(result) { 
    //success 
    $scope.bloglist = result; 
    console.log($scope.bloglist); 
    }, function(errResponse) { 
    // fail 
    }); 
});