【发布时间】:2014-04-05 08:04:52
【问题描述】:
我是 angularjs 的新手,我正在尝试从我的 json 文件中加载数据。 json 文件有一些患者列表。 但在我的视图中没有显示
这是我的“患者.json”文件
[
{
"id": 0,
"first_name": "John",
"last_name": "Abruzzi",
"middle_name": "Kewan",
"DOB": "12/03/1935",
"ssn": "254-2342-42",
"sex" : "Male",
"country" : "USA",
"city" : "Greater New York",
"phone" : "1234124822",
"military_branch" : "Army",
"zip" : "08675",
"guid" : ""
},
{
"id": 1,
"first_name": "Peter",
"last_name": "Burk",
"middle_name": "S",
"DOB": "31/06/1945",
"ssn": "342-9876-54",
"sex" : "Male",
"country" : "USA",
"city" : "New York",
"phone" : "3346573924",
"military_branch" : "FBI",
"zip" : "25643",
"guid" : ""
},
{
"id": 2,
"first_name": "Neal",
"last_name": "caffery",
"middle_name": "Sam",
"DOB": "28/02/1988",
"ssn": "420-4204-20",
"sex" : "Male",
"country" : "USA",
"city" : "New York",
"phone" : "676554323",
"military_branch" : "Air Force",
"zip" : "26531",
"guid" : ""
},
]
这是我的controller.js
var patientApp = angular.module('patientApp', []);
patientApp.controller('PatientListCtrl',['$scope','$http', function ($scope, $http) {
$http.jsonp('/json/patients.json').success(function (data) {
$scope.patients = data;
})
});
$scope.orderProp = 'id';
}]);
这是我的“index.html”文件
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" data-ng-app="patientApp">
<head>
<title>Patient Management</title>
<script src="js/angular.js"></script>
<script src="js/angular-resource.min.js"></script>
<script src="js/controller.js"></script>
</head>
<body data-ng-controller="PatientListCtrl">
<table>
<thead>
<tr>ID</tr>
<tr>First Name</tr>
<tr>Last Name</tr>
<tr>SSN</tr>
<tr>DOB</tr>
</thead>
</table>
<div data-ng-repeat="patient in patients">
<table>
<tr>{{patient.id}}</tr>
<tr>{{patient.last_name}}</tr>
<tr>{{patient.first_name}}</tr>
<tr>{{patient.SSN}}</tr>
<tr>{{patient.DOB}}</tr>
</table>
</div>
</body>
</html>
我想我错过了一些东西。 请帮助我,在此先感谢。
【问题讨论】:
-
执行 console.log($scope.patients) 会得到什么
标签: javascript html json angularjs