我有一个保存在firebase数据库中的URL列表,我试图在每个网址旁边添加一个计数,以便用户可以喜欢它们。我的$ scope.increase函数尝试用于此目的,但必定有错误,它应该增加点击次数并更新数据库。有人可以帮忙吗?
HTML
<li ng-repeat="url in urls | filter:todoSearch" class="list-item">
<div class="row">
<div class="col-md-8 link-col">
<a href="{{url.title}}" class="link">
<p class="title">{{url.name}}</p>
<p class="url">{{url.title}}</p>
</a>
<p ng-model="mvLikes" ng-click="increase($index)">0</p>
</div>
</div>
</li>
JS
var urlFire = angular.module("UrlFire", ["firebase"]);
function MainController($scope, $firebase) {
$scope.favUrls = $firebase(new Firebase('https://lloydyapp.firebaseio.com/'));
$scope.urls = [];
$scope.favUrls.$on('value', function() {
$scope.urls = [];
var mvs = $scope.favUrls.$getIndex();
for (var i = 0; i < mvs.length; i++) {
$scope.urls.unshift({
name: $scope.favUrls[mvs[i]].name,
title: $scope.favUrls[mvs[i]].title,
likes: $scope.favUrls[mvs[i]].likes,
key: mvs[i]
});
};
});
$scope.increase = function(index) {
$scope.mvLikes += 1;
var mvLikes = $scope.mvLikes;
var mv = $scope.urls[index];
var updateUrlRef = buildEndPoint(mv.key, $firebase);
updateUrlRef.$set({
likes: mvLikes
});
}
....
function buildEndPoint(key, $firebase) {
return $firebase(new Firebase('https://lloydyapp.firebaseio.com/' + key));
}