我非常简单的数据模型:
这是代码:
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title>Testing</title>
</head>
<body ng-controller="PartnerCtrl">
<div>
<li ng-repeat="item in items">{{item.Name}} - {{item.OrigBal}}</li>
</div>
<script>
var app = angular.module("bastion", ["firebase"]);
app.constant('FIREBASE_URI', 'https://notpublic.firebaseio.com/Partners');
app.controller('PartnerCtrl', [
'$scope', 'PartnerService', function($scope, PartnerService) {
$scope.newItem = { name: '', OrigBal: 0 };
$scope.currentItem = null;
$scope.items = PartnerService.getItems();
$scope.addItem = function() {
PartnerService.addItem(angular.copy($scope.newItem));
$scope.newItem = { name: '', OrigBal: 0 };
};
$scope.updateItem = function(id) {
PartnerService.updateItem(id);
};
$scope.removeItem = function(id) {
PartnerService.removeItem(id);
};
}
]);
app.factory('PartnerService', [
'$firebase', 'FIREBASE_URI', function($firebase, FIREBASE_URI) {
var ref = new Firebase(FIREBASE_URI);
var items = $firebase(ref);
var getItems = function() {
return items;
};
var addItem = function(item) {
items.$add(item);
};
var updateItem = function(id) {
items.$save(id);
};
var removeItem = function(id) {
items.$remove(id);
};
return {
getItems: getItems,
addItem: addItem,
updateItem: updateItem,
removeItem: removeItem
}
}
]);
</script>
<script src="/Scripts/angular.min.js"></script>
<script src="https://cdn.firebase.com/js/client/1.0.15/firebase.js"></script>
<script src="/Scripts/angularfire.min.js"></script>
</body>
</html>
我无法获取显示值({{item.Name}} - {{item.OrigBal}})来插入服务传回的数据。我确信它很简单,但我显然遗漏了一些必不可少的东西。任何指针都会非常感激。
答案 0 :(得分:0)
https://www.firebase.com/docs/web/libraries/angular/quickstart.html
var getItems = function() {
return items;
};
应该是
var getItems = function() {
return items.$asArray();
};
答案 1 :(得分:0)
好的,这个问题很简单,也很愚蠢。这行在javascript:
var app = angular.module('bastion', ['firebase']);
然后我在HTML中将我的ng-app定义为:
<html ng-app='myApp'>
我改为:
<html ng-app='bastion'>
现在一切正常。愚蠢的错过了我,对不起浪费任何人的时间。