我的控制器说:
app.controller("PatientsController",function ($scope, $sce, $http,$window,$timeout){
var myScope = $scope;
myScope.PatientList = [];
myScope.getPatients = function () {
$http.get('http://my-ip/dashboard/patientlist').then(function(data){
myScope.PatientList = data.data;
console.log(myScope.PatientList );
});
};
myScope.getPatients();
});
console.log有:
[{
"appointmentcount": "7",
"name": "A",
"phonenumber": "B",
"dateregistered": "2017-01-04 15:20:08"
}, {
"appointmentcount": "27",
"name": "C",
"phonenumber": "D",
"dateregistered": "2017-01-04 15:43:51"
}]
尝试使用ng-repeat检索它并没有给出任何输出:
<table class="table table-bordered table-condensed table-striped">
<div ng-repeat="pp in PatientList">
<tr>
<td>{{pp.name}} </td>
</tr>
</div> <!-- div ends -->
</table>
任何想法我错过了什么?
使用http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js
答案 0 :(得分:3)
问题在于你的表标签,在tr标签上执行ng-repeat而不是div。另外,请确保添加了 ng-app 和 ng-controller
。
<table>
<tr ng-repeat="x in PatientList">
<td>{{ x.name }}</td>
<td>{{ x.phonenumber }}</td>
</tr>
</table>
<强>样本强>
var app = angular.module("myApp", []);
app.controller("PatientsController", function($scope) {
var myScope = $scope;
myScope.PatientList = [];
myScope.PatientList = [{
"appointmentcount": "7",
"name": "A",
"phonenumber": "B",
"dateregistered": "2017-01-04 15:20:08"
}, {
"appointmentcount": "27",
"name": "C",
"phonenumber": "D",
"dateregistered": "2017-01-04 15:43:51"
}];
});
&#13;
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body ng-app="myApp" ng-controller="PatientsController">
<table>
<tr ng-repeat="x in PatientList">
<td>{{ x.name }}</td>
<td>{{ x.phonenumber }}</td>
</tr>
</table>
</body>
</html>
&#13;
答案 1 :(得分:1)
您不应在ng-repeat
内的<div>
上使用<table>
。您可能希望重复<tr>
。
<table class="table table-bordered table-condensed table-striped">
<tr ng-repeat="pp in PatientList">
<td>{{pp.name}}</td>
</tr>
</table>