firebaseArray返回长度为0

时间:2016-06-09 19:06:16

标签: angularjs firebase-realtime-database

我试图使用以下代码从firebase中找到数组的长度:

(function() {
    'use strict';

    angular
        .module('com.td.oca.tDUITestHomepage')
        .controller('HomepageController', ['$scope', '$firebaseArray', function($scope, $firebaseArray) {
            $scope.greeting = 'Hola!';
            $scope.vm = this;

            $scope.fireData = new Firebase('https://mdm-ui-test-data.firebaseio.com/');

            $scope.vm.addData = addData;
            function Data() {
                name:'';
                address:'';
                postalCode:'';
            }

            $scope.vm.newData = new Data();
            $scope.vm.dataList = $firebaseArray($scope.fireData);
            $scope.testingLength = $scope.vm.dataList.length;
            $scope.testing = $scope.vm.dataList;

        }]);

})();

然而,scope.testing返回:[{“name”:“person A”,“phone”:“11111111111”,“postalCode”:“L1T3Y2”},{“name”:“person B”,“phone” “:”222222222222“,”postalCode“:”L24YTW“},{”name“:”person C“,”phone“:”33333333333“,”postalCode“:”au43rt“}]

我相信$ scope.testingLength应该返回3的长度,然而,它返回的长度为0.有人可以解释为什么会发生这种情况吗?

1 个答案:

答案 0 :(得分:0)

按照这篇文章的建议:How to loop through $firebaseArray

我能够解决问题