following an example in an Angular book, and they have the following code:
<script>
var test = {};
var app = angular.module("app",[]);
app.run(function($http){
$http.get("/file").success(function(data){
test.input = data;
});
});
app.controller("ctrl",function($scope){
$scope.handle = test;
});
</script>
presumably data is pulled from file, pushed to the object 'test', which is then put into the scope's handle variable. The problem when I write this up, however, is that the $http.get:
app.run(function($http){
$http.get("/file").success(function(data){
test = data;
});
});
is producing the following error:
SyntaxError: Unexpected string at Object.parse (native) at vc (http://localhost/common/js/frameworks/angular.min.js:15:480) at Zb (http://localhost/common/js/frameworks/angular.min.js:82:229) at http://localhost/common/js/frameworks/angular.min.js:83:143 at m (http://localhost/common/js/frameworks/angular.min.js:7:322) at dd (http://localhost/common/js/frameworks/angular.min.js:83:125) at d (http://localhost/common/js/frameworks/angular.min.js:84:380) at http://localhost/common/js/frameworks/angular.min.js:119:113 at n.a.$get.n.$eval (http://localhost/common/js/frameworks/angular.min.js:133:221) at n.a.$get.n.$digest (http://localhost/common/js/frameworks/angular.min.js:130:233)
(anonymous function) b.$get (anonymous function)
a.$get.n.$eval a.$get.n.$digest a.$get.n.$apply h K
z.onload
which, to me, indicates that $http is not expecting a string url. Could someone explain this to me? Is the book's sample code wrong, or perhaps out of date?
edit:
the /file contents are as follows:
[{"a":"1","b":"2"},{"aa":"3","bb":"4"}]
edit 2:
From other SO articles Problems parsing a JSON response using AngularJS it looks like $http.get is supossed to be auto parsing
/file? Because I believe/fileisn't what you expect it to be.