lukassz
lukassz

Reputation: 3340

AngularJS function in factory call to query from $resource

I write simple factory which call to my rest endpont, but I would like use different address not only one, but when I execute query from $resource I get only text function in my console log.

This is my factory:

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

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

});

and my controller:

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

  function ($scope, Blog ) {

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


      console.log($scope.bloglist);

  });

How to call to different address from my factory?

Upvotes: 0

Views: 176

Answers (1)

Sumit Deshpande
Sumit Deshpande

Reputation: 2155

Try below using promise-

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

Upvotes: 1

Related Questions