Im尝试向ng-repeat创建的列表中的元素添加upvote按钮时出现问题。该清单是交易中的交易。该部分使用deal.controller和data-ng-init =“find()”。Angular - 在ng-repeat内添加upvote按钮
的deal.controller有funtion
// Find a list of Deals
$scope.find = function() {
$scope.deals = Deals.query();
};
每个元素上的按钮使用NG单击
<button ng-click="upVote(deal._id)" type="button" class="btn btn-danger
vote-up-button"><i class="glyphicon glyphicon-arrow-up"></i> Hot</button>
它调用给予好评的功能
// upVoteDeal
$scope.upVote = function (id) {
$scope.deal.votes = $scope.deal.votes+1;
var deal = $scope.deal;
deal.$update(function() {
$location.path('deals/' + deal._id);
}, function(errorResponse) {
$scope.error = errorResponse.data.message;
});
};
的问题,我有是不是说$scope.deal.votes = $scope.deal.votes+1;
是错的。
及其与TypeError: Cannot read property 'votes' of undefined
我认为你必须定义'了'$ scope.upvote'功能之外$ scope.deal.votes'像这样:'$ scope.deal = {votes:''}' –
我可能是错的,但这似乎是一个全新的交易,而不是使用列表中的交易。 – ChrisM