0

How this will work normally?

Hi I have created a simple Rest service:

@GET
@Path("/SayHello")
@Produces(MediaType.APPLICATION_JSON)
 public String sayhello(){
      String name="Hello";
      return name;
  }

And calling it using $resource from angular's MIME Service and controller like this:

service.factory('Tester', function ($resource) {
    return $resource('http://localhost:8080/Resource/rest/SayHello', {}, {
        test: { method: 'GET',isArray: false ,cache : false  },
     })
});

And in the controller I am calling a REST service through Tester Service:

Tester.test({},function success(response){
        console.log("Tester Success: "+JSON.stringify(response));
        $scope.output=response;
    },
    function error(errorResponse){
        console.log("Tester Error: "+JSON.stringify(errorResponse));
    });

Now on printing this "output" in template {{output}}

It is displaying it in json Format - {"0":"H","1":"e","2":"l","3":"l","4":"o"} rather than 'Hello'.

Using $http it working, but not using $resource. I there any solution?

Thanks in advance.

James P
  • 2,201
  • 2
  • 20
  • 30
Shubh
  • 3
  • 2
  • This is probably not angulars fault, the problem is with the server. check your server settings like content-type or encoding. – miqe May 26 '16 at 14:25

1 Answers1

0

It looks like duplicate of that question. I made quick proof of concept and I got same issue. Simply you can wrap your message into something like that

{
  "message": "Hello"
}
Community
  • 1
  • 1