0

why I can delete row in frontend but its not deleted in postgresql ? I've been copy-paste the code from other menu in my program but it not work. I've been try to search in google because I think my code is wrong but its SAME !

here is my angularJS controller

 $scope.getDataLoct = function(){
    PanelEditor.getDataLoct().then(function(result) {
        console.log('result loct',result);
        var res = result.data;
        console.log('resultdataloct', res);
            $scope.tampil= res; 
    }); 
}


   $scope.deleteVenues = function(dataD, idx){
    var dataD = $scope.tampil[idx];
    console.log('dataD',dataD);
    PanelEditor.deleteVenue(dataD).then(function(result){
        console.log('sukses');
        $scope.tampil.splice(idx, 1);       
    });
}

here is my angularJS HTML

   <div ng-model ="info"> 
      <table  class="ui celled padded table">
        <thead>
            <tr>
              <th>No</th>
              <th>Title</th>
              <th>Addres</th>
              <th>Latitude</th>
              <th>Longitude</th>
              <th>Action</th>
          </tr>
        </thead>
        <tbody class="content" ng-repeat="tmp in tampil track by $index">
            <tr>
              <td class="collapsing">
                <div class="ui ribbon label">{{$index +1}}</div>
              </td>
              <td >{{tmp.title}}</td>
              <td >{{tmp.address}}</td>
              <td >{{tmp.latitude}}</td>
              <td >{{tmp.longitude}}</td>
              <td><div class="ui small blue basic icon buttons right floated">
                  <button class="ui button" tooltips tooltip-content="Edit" tooltip-side="bottom" tooltip-speed="fast" tooltip-size="small" tooltip-hide-trigger="click mouseleave" ng-click="clickMenuVenue('loct','Edit Venue','',info)">
                    <i class="write icon"></i>
                  </button>
                  <button class="ui button" tooltips tooltip-content="delete" tooltip-side="bottom" tooltip-speed="fast" tooltip-size="small" tooltip-hide-trigger="click mouseleave" ng-click="deleteVenues($index)">
                    <i class="remove icon"></i>
                  </button>
                </div></td> 
            </tr>
        </tbody>
        </table>
    </div>

here is my angularJS service

  getDataLoct: function() {
    return $http.get('/venue/getAll/');
  },

   deleteVenue: function(dataD) {
    console.log('service',dataD);
    return $http.post('/venue/deleteVenue/',dataD);  
  }

here is my NodeJS Controller

 deleteVanue: function (req, res) {
        Vanue.destroy({id:req.param('id')}).exec(function (err){
          return res.json(200);
        });
    },
    getAll: function (req, res) {
        Venue.find().sort({ id: 'asc' }).exec(function (err, found){
            return res.json(200, found);
        });
    }

and when I clik Remove Button the Console printed this dataD undifinded

SOMEONE CAN HELP??!!

if my question have mistake please help me to fix it

2
  • do you see a request going in the console for the delete? Also, you are not posting the request param that it is looking for (id ?) you seem to be passing the data as dataD which is not the id. Commented Dec 3, 2015 at 7:40
  • hmm.. its why i ask im not understand. i ve tried to ask to my brother but he said that i should fix alone.. can you help me to tell me what should I do? :D @KashyapMukkamala Commented Dec 3, 2015 at 7:56

1 Answer 1

0

In your delete function:

$scope.deleteVenues = function(dataD, idx) {..}

you have TWO parameters in your controller.

But in the view you only call it with one parameter:

ng-click="deleteVenues($index)"

There are two options:

Either you pass the whole object which is to be deleted or you pass the $index.

Right now your app wants to read idx in the controller, but you are passing only one parameter. That's the reason why you get this error.

Sign up to request clarification or add additional context in comments.

1 Comment

oh i see ... thanks for give me a reason :) im understand now thaaankkkss :3 @FlorianTopf

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.