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.

1
  • This is probably not angulars fault, the problem is with the server. check your server settings like content-type or encoding. Commented May 26, 2016 at 14:25

1 Answer 1

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"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.