I am trying to post a simple binary value (using $http) to a URL which si defined by a value in my HTML.
I have successfully got the "card.id" being passed through (can see it in console log)
<td-card ng-repeat="card in cards"
on-destroy="cardDestroyed($index)"
on-swipe="cardSwiped($index)"
on-swipe-right="$parent.cardSwiped(card.id)"
on-swipe-left="$parent.cardSwiped(card.id)" >
The data I want to post needs to be to a URL which has the card.id in it.
How to I tell it what to post and how to trigger?
.controller('CardsCtrl', ['$scope', 'TDCardDelegate', 'cardsApi', '$http',
function($scope, TDCardDelegate, cardsApi, $http) {
console.log('CARDS CTRL');
$scope.cards = [];
$scope.onSwipeRight=function(product_id){console.log(product_id)}
//Post for swipe right {'like':1, 'uid':21}
$scope.onSwipeLeft=function(product_id){console.log(product_id)}
//Post for swipe left {'like':0, 'uid':21}
for(var i = 0; i < 7; i++) {
cardsApi.getApiData()
.then(function (result) {
$scope.cards.unshift(result.data);
$scope.product_id = result.data.product_id;
})
.catch(function (err) {
$log.error(err);
});
}
$scope.$watchCollection('cards', function (newVal, oldVal) {
if(newVal < oldVal) {
cardsApi.getApiData()
.then(function (result) {
$scope.cards.unshift(result.data);
})
.catch(function (err) {
console.log(err);
});
}
});
$scope.cardSwiped = function(card) {
console.log('here');
console.log(card);
};
//Removes card from top of stack
$scope.cardDestroyed = function(index) {
$scope.cards.splice(index, 1);
};
$scope.addCard = function() {
var newCard = $scope.cards[$scope.cards.length];
//newCard.id = Math.random();
$scope.cards.push(angular.extend({}, newCard));
};
$scope.postRecordLikes = function(product_id){
console.log(product_id)
$http.post('http://test.com/analytic/' + product_id)
.then(function successCallback(product_id) {
// this callback will be called asynchronously
// when the response is available
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
};
}
])
postRecordLikes?