0

All i want is to delete a row of a table by clicking a button. I am diong something like this

  .controller('removeInput' , function($scope, $http) {
    $scope.remove = function(index){
      var inputId = {'inputId': $scope.inputId};
      $http.delete(baseUrl + '/input/' ,inputId, _auth)
      .success(function (){
        console.log('deleted');
      }).error(function(err){
        console.log(err);
      });
    };
  });

and in html its something like this

<tbody ng-controller = "input">
 <tr ng-repeat = "inputs in inputData">
  <td ng-model = "inputId">{{inputs.inputId}}</td>
  <td><img ng-src = "{{inputs.thumbnailUrl}}"/></td>
  <td>{{inputs.filename}}</td>
  <td></td>
  <td>{{inputs.updatedAt.date}}</td>
  <td ng-controller = "removeInput">
   <a class = "btn btn-option" ng-click = "remove(index)">
    <span class = "glyphicon glyphicon-remove"></span>
   </a>
  </td>
 </tr>
</tbody>

and its not working. Please suggest where I am wrong?

5
  • what is _auth? It is undefined in code shown. Also not working isn't a proper problem statement. What do you see when you inspect the actual request in browser dev tools network tab? Should find lots of clues there Commented Jul 16, 2015 at 13:45
  • _auth is global variable containing headers Commented Jul 16, 2015 at 13:46
  • wouldn't you want remove(inputs.inputId)? Commented Jul 16, 2015 at 13:47
  • headers config for CORS is all setted in this _auth variable Commented Jul 16, 2015 at 13:47
  • @Claies yup dats what i want Commented Jul 16, 2015 at 13:47

1 Answer 1

2

You aren't really passing the correct value here. It's not clear what $scope.inputId is, but it isn't the value of the item you are trying to remove. Try this instead:

<a class = "btn btn-option" ng-click = "remove(inputs.inputId)">

and in the JavaScript:

$scope.remove = function(index){
  $http.delete(baseUrl + '/input/' + index, _auth)
  ....
Sign up to request clarification or add additional context in comments.

5 Comments

its showing Object {status: 401, message: "Given api-key is not authorized!"} in console
or maybe you still need it in object form, let me edit the javascript again
I want id with the url. something like this '/input/6654' will be the url to pass
I have my code with yours and its still giving same error
let me try to edit it one last time; what you are describing in the comments here isn't what your function was doing before.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.