I am currently working on implementing a like button feature that displays the number of likes based on the length of an array of user ids. However, I am encountering an issue where I cannot seem to save the user id to my mongoDB database. Even though the button increments properly when clicked, the user's id does not get pushed to the "likes" array within the object. Is there a way for me to append the user's id to the "likes" array within the object?
Here is my HTML code:
<button ng-model="object.likes" ng-click="addLike(object)">
<i class="material-icons">thumb_up</i>
</br>{{object.likes.length}}
</button>
And this is my JavaScript code:
app.controller('likeCtrl', function($http, $location, etc) {
$scope.addLike = function(object) {
$http.put('/objects/' + object.id, {
likes: $scope.currentUser.id
}).success(function(object) {
$scope.object.likes.push(object);
}).error(function(err) {
return alert(err.message || "an error occurred");
});
}