Sam Joni
Sam Joni

Reputation: 159

Edit and delete forms with angular, javascript

I wrote a simple code that when implemented will generate elements from the array (bookmarks), and for each element there is Edit & Delete buttons. I wrote the html code that passes the submit to a function called updatebookmark() for the edit, and deleteBookmark() for the delete, but neither buttons give a response back when clicked, this is the link to jsfiddle https://jsfiddle.net/SaifHarbia/5xds83fn/

The updateBookmark function looks like this(it is supposed to update the under-edit values and directly replace the old values on screen):

function updateBookmark(bookmark) { // updating the under-edit bookmark

        var index = _.findIndex($scope.bookmarks, function (b) {
            return b.id == bookmark.id;
        });
        $scope.bookmarks[index] = bookmark;
        $scope.editedBookmark = null;
        $scope.isEditing = false;
    } 

While the deleteBookmark function looks like this:

function deleteBookmark(bookmark) { // delete a bookmark
    var index = $scope.bookmarks.indexOf(bookmark.id);
    _.remove($scope.bookmarks, function (b) {
        return b.id == bookmark.id;

    });
}

Upvotes: 1

Views: 383

Answers (1)

Sujata Chanda
Sujata Chanda

Reputation: 3395

There was issue with your underscore file linking in fiddle. Also remove function was not proper. Check this Fiddle

Remove functionality:-

function deleteBookmark(bookmark) { // delete a bookmark
        var index = $scope.bookmarks.indexOf(bookmark.id);
      $scope.bookmarks =  _.reject($scope.bookmarks, function (b) {
            return b.id == bookmark.id;

        });
    }

Upvotes: 1

Related Questions