我是新角度。我試圖在firebase中使用angular foreach,但它不起作用。如何做到這一點的任何指針?如何使用角色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" },
...]
你肯定角火和火力地堡被納入正常嗎? –
是的,很確定。我可以從firebase獲取數據,$ scope.menu正常工作。 – user3831592
任何控制檯錯誤? – V31