【发布时间】:2016-06-09 19:06:16
【问题描述】:
我正在尝试使用以下代码从 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。谁能解释为什么会这样?
【问题讨论】:
标签: angularjs firebase-realtime-database