AngularJS post updated data to php page via $ http.post

I just added functionality to edit table cell in my angularJS app. Now I would like to see the changes reflected in the database by sending the updated data to my PHP script, I am a bit stuck on how to actually send the updated table.

My Angular Table in question:

<tr ng-repeat="c in resultValue=(data | filter:{'type':typeFilter} | filter:dateFilter | filter:proFilter | filter:cusFilter | filter:taskFilter | filter:nameFilter)">

    <td class="jid" ng-hide="viewField">{{c.journal_id}}</td>
    <td ng-show="modifyField"><input type="text" class="in1" ng-model="c.journal_id" /></td>

    <td class="wda" ng-hide="viewField">{{c.work_date}}</td>
    <td ng-show="modifyField"><input type="text" class="in1" ng-model="c.work_date" /></td> 

</tr>
     <button ng-hide="viewField" ng-click="modify(c)">Modify</button>
     <button ng-show="modifyField" ng-click="update(c)">Update</button>

      

Controller thanks to SO answer for the edit part:

    journal.controller('dbCtrl', ['$scope', '$http', function ($scope, $http) {

          $scope.loadData = function () {
        $http.get("http://localhost/slick/journalFetch.php").success(function(data){
                $scope.data = data;
            }).error(function() {
                $scope.data = "error in fetching data";
            });
}

  $scope.modify = function(c){

            $scope.modifyField = true;
            $scope.viewField = true;
        };


  $scope.update = function(c){
            $scope.modifyField = false;
            $scope.viewField = false;

          //AM I ABLE TO RESEND THE UPDATED (c) DATA HERE TO THE DATABASE ?

             $http({
                method: "post",
                url: "update.php",
                data: {
                    //if so how to retrieve updated c data here?
                }
             }); 
            };
  $scope.loadData();
}]);

      

+3


source to share


1 answer


It looks like you are trying to update the entire table with the click of a button Update

. Your current code is trying to access c

outside of the element tr

, making it c

unavailable for button

.



Try passing a variable data

to a function Update

.

0


source







All Articles