Javascript 带按钮的AngularJS单项目更新
好的,我在Firebase中有一个产品阵列Javascript 带按钮的AngularJS单项目更新,javascript,angularjs,firebase,Javascript,Angularjs,Firebase,好的,我在Firebase中有一个产品阵列 products -JpzIlrpRfXzx5HbZMw_ description: 'The description to the product' image: 'The link to the product image' likes: '0' price: '15' title: 'The product title 我想给每个产品添加一个“like”按钮。每次单击按钮时,需要将上述值增加一个 我已
products
-JpzIlrpRfXzx5HbZMw_
description: 'The description to the product'
image: 'The link to the product image'
likes: '0'
price: '15'
title: 'The product title
我想给每个产品添加一个“like”按钮。每次单击按钮时,需要将上述值增加一个
我已经找到了如何使用输入来完成这项工作,您可以输入类似的内容,但这不是很友好
<input type="text" ng-model="product.likes" ng-change="products.$save(product)"/>
如何将输入更改为按钮?单击时,将整数之类的乘积增加1。应该非常简单:
<input type="button" ng-click="product.likes += 1; products.$save(product);"/>
注意:我建议您将其提取到函数中只需将
product.likes
增加一个,然后将您的产品对象发回数据库
这会导致语法错误吗?您需要使用递增计数器,否则并发编辑将有问题。
<button type="button" ng-click="products.$save(product)">Save </button>
<p>{{product.likes}}</p>
$scope.products = {
$save : function(product) {
product.likes += 1;
//post your product
}
}