I am trying to get the JSON data using the $http function; I am always getting error for this. Here is my HTML code:
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<ul>
<li ng-repeat="x in code">
{{ x.code }}
</li>
</ul>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("data.json")
.success(function (response) {$scope.code = response;})
.error(function (response) {alert("Error")})
});
</script>
</body>
</html>
Here is my data.json file:
{
"code":"#include <stdio.h>
int main()
{
printf('Hello world');
return 0;
}"
}
Here is the plunker http://plnkr.co/edit/Q4dsCjHM3ykgp2SaHw35?p=preview