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

标签 javascript angularjs angularjs-ng-repeat ngresource

在我的 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/

相关文章:

javascript:检查表达式是否可评估?

javascript - 如何根据条件jquery将表单提交给不同的函数

javascript - 选择前一个父jQuery的 child

javascript - AngularJS 服务不显示

javascript - 单击按钮/链接后更改 ng-include 中的内容

AngularJs 无法访问 Controller 中的表单对象($scope)

javascript - 在使用 jquery 验证电子邮件后添加一个类

angularjs - Angular ng-repeat 按格式化日期过滤/搜索

javascript - 过滤搜索 AngularJS

javascript - 从自定义指令访问 ng-repeat 索引值