我建立了一个名为“Data”的工厂。我可以在控制器如下使用:
控制器
myApp.controller('MyController', ['$scope', '$firebase', 'Data', function($scope, $firebase, Data) {
// OTHER REFS/FIREBASE
$scope.entries = Data;
}]);
的index.html
<div ng-repeat="entry in entries">
{{entry.name}}
</div>
工厂
myApp.factory('Data', ['$http', function ($http) {
// load the data
var entriesz = [];
$http.get('data/main.json').success(function(data) {
angular.forEach(data.ParkingFacilities, function(entry) {
$http.get(entry.staticDataUrl).success(function(data) {
entriesz.push(angular.extend(entry, data.parkingFacilityInformation));
});
});
});
//window.alert("Data Imported :" + entriesz.length);
//window.alert(JSON.stringify(entriesz))
return entriesz;
// parse it and store it on firebase
}]);
我现在想知道如何使用此工厂在我的Firebase存储中更新它,并创建可访问此存储数据的附加控制器。
P.s.如果您想知道为什么我不使用上述示例中的工厂,基本上,检索数据需要很多计算时间,所以为了节省一些计算时间,我想分割后端和前端进程。
请编辑博文,包括数据的工厂代码,在至少可以让我们理解你的问题的最小部分。 – 2014-12-05 16:23:57
包括工厂。使用entriesz有很多困难... typeof是未定义的,数组的长度显然为0.但是,当我放入$ scope.entries = entriesz,然后返回到我的index.html并写入{{条目[0]}}然后它显示在我的第一个数组项目中的对象。但似乎在控制器entriesz [0]不起作用......这很奇怪! – JohnAndrews 2014-12-05 16:28:36