I want to get a live update of records when a new record is inserted into the db. when a new record is inserted i want the div containing the item in cart to refreshed
.controller('newitem_ctrl', ['$scope', '$http', function($scope, $http) {
$http.get('http://localhost/spree/work/items/item.php').success(function(data) {
$scope.cart = data;
});
$scope.newitem = function() {
$ionicLoading.show({
template: '<p>Wait...</p><ion-spinner></ion-spinner>'
});
event.preventDefault();
$http.post("http://localhost/work/scripts/new_payment.php", {
'item': $scope.item
})
.success(function(data, status, headers, config) {
console.log(data)
}).error(function(error) {
console.error(error);
});
};
}]);
HTML
<div ng-controller="newitem_ctrl">
<form method="post">
<input type="text" name="item_name" placeholder="Item Name" ng-model="item" />
<button class="button button-balanced" ng-click="newitem()">Add</button>
</form>
<div ng-repeat="item in cart">
{{item.product_name}}
</div>
</div>