【发布时间】:2014-07-12 05:22:38
【问题描述】:
我是角度新手。我正在尝试将 Angular foreach 与 Firebase 一起使用,但它没有用。有关如何执行此操作的任何指示?
var app = angular.module('MyApp',["firebase"]);
app.controller('ItemCtrl', function($scope, $firebase){
var ref = new Firebase("https://url.firebaseio.com");
$scope.menu = $firebase(ref);
$scope.total = function(){
var total = 0;
angular.forEach($scope.menu, function(item) {
total += item.price * item.quantity;
})
return total;
};
});
html
<div class=" sliding" >
<a href="#"class="button open" >
Total: {{total() | currency}}
</a>
</div>
json
[
{"name": "Ham, Egg & Cheese CROISSAN'WICH ",
"quantity": 0,
"price": 20,
"description": "description",
"comment": "comment",
"imgURL": "http://url" },
...]
【问题讨论】:
-
您确定正确包含 angular fire 和 Firebase 吗?
-
是的,很确定。我可以从 firebase 获取数据,$scope.menu 工作正常。
-
错误:[$interpolate:interr] 无法插值:总计:{{total() |货币}} ReferenceError: total 未定义
-
您的视图如何?
标签: javascript angularjs firebase angularfire