0

I am removing a row from an angularjs table using this code:

$scope.removeRow = function (index) {
if (index === -1) {
alert("Something gone wrong");
}else{
$scope.budgetdetails.splice(index,1);
}

However my json data and database are not updating. What do I need to do to update the data in both of them?

mdiaz
  • 27
  • 1
  • 10
  • Need to send that information to server using `$http` and server would update database. In order to do that you need to pass in whole object to your function so you have id to send ... then index it yourself – charlietfl Jul 02 '16 at 17:03
  • Thank you charlieftl. I was reading about that. Is there a good example you could point me to? – mdiaz Jul 02 '16 at 17:18
  • this will help. use it inside your ajax promise callback http://stackoverflow.com/questions/15453979/how-do-i-delete-an-item-or-object-from-an-array-using-ng-click/15454424#15454424 – charlietfl Jul 02 '16 at 17:36

3 Answers3

0

smth like this: Auto select and collect checkbox values in array

$scope.getData = function(Day) {
var index = $scope.budgetdetails.indexOf(Day);

if (index < 0) {
  $scope.budgetdetails.push(Day)
  console.log('myData', $scope.budgetdetails);
} else {
  $scope.budgetdetails.splice(index, 1)
  console.log('myData',$scope.budgetdetails);
}

}

Community
  • 1
  • 1
Prianca
  • 484
  • 2
  • 8
  • Hi Prianca, this code removes the row from my angular table. However bottom-line it does the same my code was doing. My json is still not updating and the rows in my database remain the same. Mansa suggested to use $http for that. Do you have any advice? – mdiaz Jul 03 '16 at 00:14
0

To update in database, you need to use $http service (https://docs.angularjs.org/api/ng/service/$http ) and your Api should handle this code .

 $http({
      method  : 'POST',
      url     : '//http://localhost/MyAPI/MyRoute',
      data    : $scope.budgetdetails, //forms user object
      headers : {'Content-Type': 'application/json'} 
     })
      .success(function(data) {
        if (data.errors) {
          // Showing errors.            
        } else { //success message for API
          $scope.message = data.message;
        }
      }
Prianca
  • 484
  • 2
  • 8
0

I have figured this out. I followed this tutorial

Angular-js-with-ASP-NET-MVC-Insert-Update-Delete

mdiaz
  • 27
  • 1
  • 10