我是angularjs
的新手,我正在尝试学习它。在使用 Ajax $http 服务的小型练习应用程序时,我遇到了以下错误。下面是我使用过的代码。
<script type="text/javascript">
var app=angular.module("angulardata",[]);
app.controller("angulardata",["$scope","$http",function($scope,$http)
{
$http.get('employee.json').then(function(response){
$scope.employees=response;
});
}]);
</script>
</head>
<body ng-app="angulardata" ng-controller="angulardata">
<h2>Employee Data</h2>
<table>
<tr ng-repeat="emp in employees">
<td>{{emp.firstname}}</td>
<td>{{emp.lastname}}</td>
<td>{{emp.Age}}</td>
<td>{{emp.salary}}</td>
</tr>
</table>
最佳答案
您的 json 文件无效: 尝试使用这个
[
{ "firstname":"Gunjan", "lastname":"Limbachiya", "Age":30, "salary":50000},
{ "firstname":"Pramod", "lastname":"Limbachiya", "Age":57, "salary":70000 },
{ "firstname":"Kashyap", "lastname":"Limbachiya", "Age":28, "salary":60000 },
{ "firstname":"Malhar", "lastname":"Limbachiya", "Age":30, "salary":220000 }
]
您可以随时检查您的 json 是否正确:https://jsonformatter.curiousconcept.com/
关于angularjs - 错误: [$http:baddata] error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46074382/