Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 我的循环仅显示我的视图中的最后一个数据值-firebase_Html_Angularjs_Firebase_Firebase Realtime Database - Fatal编程技术网

Html 我的循环仅显示我的视图中的最后一个数据值-firebase

Html 我的循环仅显示我的视图中的最后一个数据值-firebase,html,angularjs,firebase,firebase-realtime-database,Html,Angularjs,Firebase,Firebase Realtime Database,我试图显示使用angular.foreach从firebase数据库检索到的所有设备列表,但当我试图在视图中显示检索到的值时,它只显示最后一个值。需要帮助 我的JS 我的html 控制台日志: 视图: 这是因为每次迭代都会更改$scope.allEquipments的值。您需要将其推入数组中 app.controller('sdtCtrl', ['$scope', '$firebaseObject', '$firebaseArray', function ($scope, $firebaseOb

我试图显示使用angular.foreach从firebase数据库检索到的所有设备列表,但当我试图在视图中显示检索到的值时,它只显示最后一个值。需要帮助

我的JS

我的html

控制台日志:

视图:


这是因为每次迭代都会更改$scope.allEquipments的值。您需要将其推入数组中

app.controller('sdtCtrl', ['$scope', '$firebaseObject', '$firebaseArray', function ($scope, $firebaseObject, $firebaseArray) {
    'use strict';

    // Add this line
    $scope.allEquipments = [];
    var ref = firebase.database().ref();
        var data = ref.child("data");
        var list = $firebaseArray(data);

        list.$loaded().then(function(data) {
            $scope.data = data;
            angular.forEach ($scope.data , function (d) {
                angular.forEach (d.equipments, function (e) {
                    // Change this line
                    $scope.allEquipments.push(e);
                    console.log($scope.allEquipments);
                })
            });
            console.log($scope.data);
        }).catch(function(error) {
            $scope.error = error;
        });
}]);
你的ng重复给我听

非常感谢。
<div class="table-responsive">
  <table class="table table-striped table-hover">
     <tr>
        <th id="system">System</th>
        <th id="equipment">Equipment</th>
        <th id="date">Date</th>
        <th id="type">Type</th>
     </tr>
     <tr data-ng-repeat="d in allEquipments">
        <td headers = "system">System</td>
        <td headers = "equipment" >{{d}}</td>
        <td headers = "date">date</td>
        <td headers = "type">Standby</td>
     </tr>
  </table>
app.controller('sdtCtrl', ['$scope', '$firebaseObject', '$firebaseArray', function ($scope, $firebaseObject, $firebaseArray) {
    'use strict';

    // Add this line
    $scope.allEquipments = [];
    var ref = firebase.database().ref();
        var data = ref.child("data");
        var list = $firebaseArray(data);

        list.$loaded().then(function(data) {
            $scope.data = data;
            angular.forEach ($scope.data , function (d) {
                angular.forEach (d.equipments, function (e) {
                    // Change this line
                    $scope.allEquipments.push(e);
                    console.log($scope.allEquipments);
                })
            });
            console.log($scope.data);
        }).catch(function(error) {
            $scope.error = error;
        });
}]);
 <tr data-ng-repeat="d in allEquipments">
    <td headers = "system">System</td>
    <td headers = "equipment" >{{d.equipment}}</td>
    <td headers = "date">date</td>
    <td headers = "type">Standby</td>
 </tr>