Angularjs ng-repeat 指令问题

Angularjs ng-repeat directive issue

index.html

{% extends "base.html" %}
{% block header %}

{% endblock %}

{% block body %}
    <div ng-controller="SCTestList">
        [[messages]]
        <tr ng-repeat="item in messages">
          <td>[[item.id]]</td>
          <td>[[item.carrier]]</td>
          <td>[[item.phoneNumber]]</td>
          <td>[[item.shortcode]]</td>
          <td>[[item.sentTime]]</td>
          <td>[[item.MOs]]</td>

        </tr>
    </div>
<script src="{{url_for('static', filename='js/test.js')}}"></script>


{% endblock %}

test.js

var myApp = angular.module('myApp', [], function($interpolateProvider) {
    $interpolateProvider.startSymbol('[[');
    $interpolateProvider.endSymbol(']]');
});

function SCTestList($scope, $http) {
    $http.get('http://localhost:5000/api/MT').
        success(function(data) {
            $scope.messages = data.json_list;
        });
}

SCTestList.$inject = ['$scope'];
angular.module('myApp').controller('SCTestList', ['$scope', '$http', SCTestList]);

json return 来自 http 请求

{
  "json_list": [
    {
      "MOs": [
        {
          "id": 3,
          "incomingTime": "2016-02-17 03:22:55",
          "msgID": 123123132123,
        },
        {
          "id": 2,
          "incomingTime": "2016-01-17 03:22:55",
          "msgID": 123123132123,
        }
      ],
      "id": 1,
      "msgID": 123123132123,
      "sentTime": "2016-01-17 03:22:55",
    },
    {
      "MOs": [],
      "id": 2,
      "msgID": 123123132143,
      "sentTime": "2016-01-17 03:22:55",
    }
  ],
  "totalPages": 1
}

页面输出

[{"MOs":[{"id":3,"incomingTime":"2016-02-17 03:22:55","msgID":123123132123},{"id":2,"incomingTime":"2016-01-17 03:22:55","msgID":123123132123}],"id":1,"msgID":123123132123,"sentTime":"2016-01-17 03:22:55"},{"MOs":[],"id":2,"msgID":123123132143,"sentTime":"2016-01-17 03:22:55"}] 

显然,消息对象在范围内,因为它正在文档上输出,但由于某种原因,我无法让应用程序遍历数组元素。我在这里遗漏了什么吗?

如果我在 ng-repeat 指令中打印 $index,我没有看到任何打印出来的东西,所以它根本没有循环。

您的标记不正确,div 中有一个 tr。将 tr 包裹在 table 中以获得有效标记。