gpt4 book ai didi

javascript - AngularJS - $resource + ng-repeat 问题

转载 作者:行者123 更新时间:2023-11-28 07:40:17 24 4
gpt4 key购买 nike

在我的 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');
});

大多数时候表格渲染得很好:

Correct rendering

但我注意到,当我重新加载页面几次时,表格有时看起来像这样:

Incorrect rendering

我认为当$resource$promise仍未解决时ng-repeat开始时就会出现问题。因此,我在返回讲师列表的后端方法中设置了断点。当执行停止时,页面上仅呈现表头。当继续执行并从服务器发送数据时,表格呈现得很好。我觉得很奇怪。

最佳答案

感谢您的回答。

我仔细查看了后端调用了哪些方法。这实际上是一个罕见的服务器端问题,导致路由困惑。

关于javascript - AngularJS - $resource + ng-repeat 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28112078/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com