0

I am using AngularJS and currently working with static text files to get data. I used factory to return a $resource as,

app.factory('TimeSeriesData', function ($resource) {

   return $resource('data/timeSeriesData.txt');

});

I also tried to $http but AngularJS was trying to parse it as JSON using this function in angular.js

function fromJson(json) {
  return isString(json)
      ? JSON.parse(json)
      : json;
}

I just have plain text data in the text file which is not in a JSON format. The parsing is causing an error in the console. How do I avoid AngularJS to stop parsing it as JSON ?

lostpacket
  • 1,383
  • 8
  • 26
  • 38
  • It's not implemented yet in the frozen builds. This should work correctly assuming correct headers if you try to build Angular yourself or grab it from GitHub. – Benjamin Gruenbaum Aug 19 '13 at 21:16
  • Found it! possible duplicate of [How to specify headers parameter for custom Angular $resource action](http://stackoverflow.com/questions/12791667/how-to-specify-headers-parameter-for-custom-angular-resource-action) – Benjamin Gruenbaum Aug 19 '13 at 21:17
  • Try send with the header `Accept: text/plain`. If you use 1.0.7, then use `$http instead`. – zs2020 Aug 19 '13 at 21:21
  • Yes, that seems to be the only way. If I use the $httpProvider to override defaults, then I have other calls to server that indeed return JSON. So do I need to change the defaults every time before I send the request to the server ? – lostpacket Aug 19 '13 at 22:09
  • Please ignore my comment above. Thanks. – lostpacket Aug 19 '13 at 22:12

0 Answers0