Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am new to AngularJS, and building an app that will interact with a server. The server has a REST API, but responds to some methods with plain text, and to others with JSON. I have implemented a simple http request method using AngularJS' $resource service.

However, when the server response is plain text, the response in AngularJS is an object with one entry for each character in the response word. How can I get around this (in a good way)? Ideally, I would like to be able to tell my service when to expect plain text and when to expect JSON, and get a nicely formatted response in both cases.

share|improve this question
add comment (requires an account with 50 reputation)

1 Answer

up vote 0 down vote accepted

$resource is a convenience wrapper for working with Restful objects. It'll automatically try to parse as JSON and populate the object based on the $resource definition.

You are much better off using the $http service for non restful resources.

This is a lower level API that doesn't have such overbearing object mapping.

e.g.

$http({method: "GET", url: "/myTextDocURL"}
  .success(function(data){ // data should be text string here }
);
share|improve this answer
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.