I am building an Angular app. The computer I have is not connected to the Internet.
I tried to read a json file I created locally.
I tried with $http.get and I failed. Got cross origin error.
I read a little bit more and tried the JSONP request. I can see that i can now access to the json file, but the file is not read as I accepted.
It seems to me that the the browser doesn't understand to parse it as Json file.
What should I do?
Directive:
app.directive("Directive", ["Service", function(Service){
return {
restrict: "E",
templateUrl: "views/template.tpl.html",
link: function(scope, element, attributes){
scope.populateInfo = function(){
var appData = Service.populateData();
}
}
}
}])
The Service:
app.service('Service', ['$http', function(http){
this.populateData = function(){
var url = "assets/mock.json";
$http.jsonp(url).then(function(response){
var result = response.data;
});
}
}]);
I do not access to the .then. I got an error "Uncaught SyntaxError": Unexpected token :
mock.json:
{
"A": [
{
"name": "a",
"id": 1
},
{
"name": "b",
"id": 2
}
]
}