使用 Firebase 和 Angular 填充数据表

populating datatable with Firebase and Angular

我对 Firebase 和整个 web 开发技巧还很陌生。

我正在尝试使用我的 Firebase 中的数据填充我网站中的数据表。

This is the datatable in bootstrap

以下是app.js

var app = angular.module("aocgApp", ["firebase"]);
app.controller("dataController", ["$scope", "$firebaseArray", 
function($scope, $firebaseArray) {
    var national = new Firebase("https://aoconsultinggroup.firebaseio.com/National");
    $scope.schools = $firebaseArray(national);
}]);

最后,html 代码:

<div class="panel-body">
<div ng-app="aocgApp" ng-controller="dataController">
<div class="table-responsive">
    <table class="table">
        <thead>
            <tr>
                <th>School Name</th>
                <th>SATs</th>
                <th>GPA</th>
                <th>Tuition</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="school in schools">
                <td>{{ schools.name }}</td>
                <td>{{ schools.sat24l }}</td>
                <td>{{ schools.gpa }}</td>
                <td>{{ schools.tuition }}</td>
            </tr>
        </tbody>
    </table>
</div>
</div>
</div>

感谢您的帮助。

编辑:以下是数据结构

 aoconsultinggroup
  L Business
  L CS
  L Engineering
  L National
    L 0
       L name
       L SAT
       L GPA
       L tuition
    L 1
       L name
       L SAT
       L GPA
       L tuition
    L 2
       L name
       L SAT
       L GPA
       L tuition
    L 3
       L name
       L SAT
       L GPA
       L tuition

您的模板中的变量名称有误,是 schools 而不是 national:

<tr ng-repeat="school in schools">
  <td>{{ school.name }}</td>
  <td>{{ school.sat24l }}</td>
  <td>{{ school.gpa }}</td>
  <td>{{ school.tuition }}</td>
</tr>

在你的控制器中,你不需要使用$loaded()。下载数据后,$firebaseArray() 将触发 $digest 循环。

你只需要这个:

var national = new Firebase("<your-firebase-app>/National");
$scope.schools = $firebaseArray(national);

这就是 school in schools 在模板中工作的原因。 schools变量来自控制器的$scopeschool变量是在模板中创建的