我是新角度。我试图在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