在我的 html 文件中,我有下表:
<div ng-controller="InstructorCtrl">
<table class="table table-bordered">
<thead>
<tr>
<th>Title</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="instructor in instructors">
<td>{{instructor.title}}</td>
<td>{{instructor.name}}</td>
</tr>
</tbody>
</table>
</div>
Controller 的外观如下:
angular.module('angularFrontendApp')
.controller('InstructorCtrl', function ($scope, Instructor) {
$scope.instructors = [];
$scope.instructors = Instructor.query();
});
注入(inject)的Instructor
是工厂:
angular.module('angularFrontendApp')
.factory('Instructor', function ($resource) {
return $resource('http://localhost:9000/api/instructor');
});
大多数时候表格渲染得很好:
但我注意到,当我重新加载页面几次时,表格有时看起来像这样:
我认为当$resource
的$promise
仍未解决时ng-repeat
开始时就会出现问题。因此,我在返回讲师
列表的后端方法中设置了断点。当执行停止时,页面上仅呈现表头。当继续执行并从服务器发送数据时,表格呈现得很好。我觉得很奇怪。
最佳答案
感谢您的回答。
我仔细查看了后端调用了哪些方法。这实际上是一个罕见的服务器端问题,导致路由困惑。
关于javascript - AngularJS - $resource + ng-repeat 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28112078/