I am new to angularjs and I've been searching on the web the whole day just to find a solution in getting data from a local json file without having to use a localhost for my webapp. Unfortunately, I haven't found any. I tried using $http.get but I get Cross Origin * error.
Is there no other way that I could get the data from my local json file without having to locally host my webapp?
Does angularjs have any other function to get data from local json files without having to use its $http.get?
You can refer to json file calling them with a GET
method, like so:
$http.get('phones/phones.json').success((data) => {
$scope.phones = data;
});
Check the official AngularJS tutorial to see what you are doing wrong.
Update:
For angular 1.6+ success
method is not valid anymore instead use then
:
$http.get('phones/phones.json').then((data) => {
$scope.phones = data;
});
Refer to source here.
You need to deploy your application to some http server, the easiest way to this is using node, here is the exmaple https://www.npmjs.org/package/http-server, or you can change you browser security settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With