Help! I got troubles with my AngularJS delete(by.id)

25 views
Skip to first unread message

Mathias Christensen

unread,
May 15, 2014, 7:45:59 AM5/15/14
to ang...@googlegroups.com
Hello everyone! I'm using Couchdb to store my data. and createNewCustomer + the list of customers works fine. I need help to delete.

This is my ng-click:


    ---->>        <td><a ng-click="remove(customers.id)" class="btn btn-small btn-danger" style="width:100px;">Delete {{customers.doc.company}}</a></td>

I've tried a lot of stuff inside my controller, and this is what I got so far. This is both the listing and now I want to add the delete function inside same ctrl.:


var customerListApp = angular.module('customerListApp', []);

customerListApp.controller('customerListCtrl', ['$scope', '$http',
    function (scope, http) {

        scope.customerList = data.rows;

        scope.sortField = 'company';
        scope.reverse = true;

---------------vvvvvvvvvvvvvvvvvvv---------------------------

        scope.remove = function (id) {
            for (i in customers) {
                if (customers[i].id == id) {
                    customers.splice(i, 1);
                }
            }
        }



    });
    }]);



It seems like nothing is happening when I click the button. Help! :)

Filipe Monteiro

unread,
May 15, 2014, 8:09:19 AM5/15/14
to ang...@googlegroups.com
Your scope functions are inside of your http.get success. You should put those functions out of this promise.
Message has been deleted

Mathias Christensen

unread,
May 15, 2014, 8:16:12 AM5/15/14
to ang...@googlegroups.com
Hello. I've done that now, but still doesn't work. Should my delete form look different? Should I store my data somehow or anything?


Den torsdag den 15. maj 2014 14.09.19 UTC+2 skrev Filipe Monteiro:
Your scope functions are inside of your http.get success. You should put those functions out of this promise.

Em quinta-feira, 15 de maio de 2014 08h45min59s UTC-3, Mathias Christensen escreveu:
Hello everyone! I'm using Couchdb to store my data. and createNewCustomer + the list of customers works fine. I need help to delete.

This is my ng-click:


    ---->>        <td><a ng-click="remove(customers.id)" class="btn btn-small btn-danger" style="width:100px;">Delete {{customers.doc.company}}</a></td>

I've tried a lot of stuff inside my controller, and this is what I got so far. This is both the listing and now I want to add the delete function inside same ctrl.:


var customerListApp = angular.module('customerListApp', []);

customerListApp.controller('customerListCtrl', ['$scope', '$http',
    function (scope, http) {

        scope.customerList = data.rows;

        scope.sortField = 'company';
        scope.reverse = true;
    });
---------------vvvvvvvvvvvvvvvvvvv---------------------------

        scope.remove = function (id) {
            for (i in customers) {
                if (customers[i].id == id) {
                    customers.splice(i, 1);
                }
            }
        }




    }]);

Filipe Monteiro

unread,
May 15, 2014, 8:17:21 AM5/15/14
to ang...@googlegroups.com
have you tried like this:

customerListApp.controller('customerListCtrl', ['$scope', '$http',
    function (scope, http) {

        scope.remove = function (id) {
            for (i in customers) {
                if (customers[i].id == id) {
                    customers.splice(i, 1);
                }
            }
        }

        scope.customerList = data.rows;

        scope.sortField = 'company';
        scope.reverse = true;
    });


    }]);

It should work.


2014-05-15 9:13 GMT-03:00 Mathias Christensen <mathias...@gmail.com>:
I've done that, but still not working. I do have in mind, that maybe I should store my data before it can get it by id or something? I'm quite new to angularjs :/


Den torsdag den 15. maj 2014 14.09.19 UTC+2 skrev Filipe Monteiro:

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/CGfo4fBKm4k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Mathias Christensen

unread,
May 15, 2014, 8:34:29 AM5/15/14
to ang...@googlegroups.com
I just tried that, and still doesn't seem to work. But I figured something out. I tried this:

var customerListApp = angular.module('customerListApp', []);

customerListApp.controller('customerListCtrl', ['$scope', '$http',
    function (scope, http) {

        scope.customerList = data.rows;

        scope.sortField = 'company';
        scope.reverse = true;
    });

        scope.remove = function (id) {
            scope.customerList.splice(id, 1)
        }

    }]);


This little form -  scope.remove = function (id) {
            scope.customerList.splice(id, 1)
        }
- Deletes the object from the view which I wanted it to. BUT, when I refresh the page, the data comes back. I want to delete the information completely from couchdb. Any advice here?

Filipe Monteiro

unread,
May 15, 2014, 8:41:16 AM5/15/14
to ang...@googlegroups.com
you need to call some function (rest, for example) to delete this register in your database, the angular part is working perfectly.
Reply all
Reply to author
Forward
0 new messages