PapaParse 生成的数组未填充 ng-repeat

Resulting array from PapaParse not filling out ng-repeat

我正在尝试上传一个 csv,然后 运行 通过 PapaParse 将其上传到 JSON。在 PapaParse 之后,我将它存储为 $scope.dataTable 并正确地登录到控制台,但它没有填充我的 ng-repeat,我不知道为什么。

var app = angular.module('rainApp', []);
app.controller('mainCtrl', function($scope) {
    $scope.dataTable = [];

    $scope.csv = document.getElementById("file-input");

    function buildTable(a) {
        $scope.dataTable = a;
        console.log($scope.dataTable);
    }

    function dataToJson(data, callback) {
        Papa.parse(data, {
            header: false,
            complete: function(results) {
                callback(results.data);
            }
        });
    }

    $scope.csv.addEventListener("change", function() {
        data = this.files[0];
        dataToJson(data, buildTable);
    });
});

和HTML(我加载上面的angular脚本)

  <div ng-controller="mainCtrl">
    <input id="file-input" type="file" accept=".csv" />
<div ng-repeat="item in dataTable">
  <h1>{{item}}</h1>
</div>

  </div>

来自 console.log

的 JSON 的内容
[
  {
    "Township": "T024R01W5",
    "Date": "1955-01-01",
    "Precip. (mm)": "0.8"
  },
  {
    "Township": "T024R01W5",
    "Date": "1955-01-02",
    "Precip. (mm)": "0.3"
  },
  {
    "Township": "T024R01W5",
    "Date": "1955-01-03",
    "Precip. (mm)": "0.0"
  },
  {
    "Township": "T024R01W5",
    "Date": "1955-01-04",
    "Precip. (mm)": "0.0"
  },
  {
    "Township": "T024R01W5",
    "Date": "1955-01-05",
    "Precip. (mm)": "0.0"
  },
  {
    "Township": "T024R01W5",
    "Date": "1955-01-06",
    "Precip. (mm)": "0.0"
  },
  {
    "Township": "T024R01W5",
    "Date": "1955-01-07",
    "Precip. (mm)": "0.0"
  },
  {
    "Township": "T024R01W5",
    "Date": "1955-01-08",
    "Precip. (mm)": "0.0"
  },
  {
    "Township": "T024R01W5",
    "Date": "1955-01-09",
    "Precip. (mm)": "0.0"
  },
  {
    "Township": "T024R01W5",
    "Date": "1955-01-10",
    "Precip. (mm)": "0.0"
  },
  {
    "Township": "T024R01W5",
    "Date": "1955-01-11",
    "Precip. (mm)": "0.0"
  },
  {
    "Township": "T024R01W5",
    "Date": "1955-01-12",
    "Precip. (mm)": "0.0"
  },
  {
    "Township": "T024R01W5",
    "Date": "1955-01-13",
    "Precip. (mm)": "2.3"
  },
  {
    "Township": "T024R01W5",
    "Date": "1955-01-14",
    "Precip. (mm)": "0.0"
  },
  {
    "Township": "T024R01W5",
    "Date": "1955-01-15",
    "Precip. (mm)": "0.0"
  },
  {
    "Township": "T024R01W5",
    "Date": "1955-01-16",
    "Precip. (mm)": "0.0"
  },
  {
    "Township": "T024R01W5",
    "Date": "1955-01-17",
    "Precip. (mm)": "0.8"
  },
  {
    "Township": ""
  }
]

$scope.dataTable之后=一个; 尝试添加这个新行:

$scope.$apply();