I would like to instantly update {{card.likeCount}} (on the HTML page) when user click on like anchor tag.
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>
<li>
<i class="fa fa-eye">
</i>
{{card.likeCount}}
</li>
<li>
<a href="#" ng-click="likingCard(card.id)" name>
Like
</i>
</a>
</li>
This is how I currently do it, I add this code to cardCtrl, I'm not sure if I'm using the right approach:
$scope.likingCard = function(id) {
$http.post('/card/like/', {
id: id
}).then(function onSuccess(result, status, headers, config) {
setTimeout(function() {
$scope.likeCount = parseInt(result.data.likeCount);
console.log($scope.likeCount);
$scope.$digest();
}, 1000);
}).catch(function onError(err) {
console.log('Error:', err);
})
}