In this tutorial, we will learn add, edit and delete functionality into angularjs application.We will add functionality of add record, edit record and delete record on grid listing.Angular provide very simple logic on behind add/edit and delete functionality, If you have knowledge of JSON object/Array then you can do it with in minute, you learn within five minute to add/edit and delete functionality on angular.
Step 1: We will add add,edit and delete icon on table list.I am using bootstrap3 lib so here i am using class of bootstrap.
<div class="btn-group"> <button type="button" class="btn btn-default btn"><i class="glyphicon glyphicon-pencil"></i></button> <button type="button" class="btn btn-default btn"><i class="glyphicon glyphicon-trash"></i></button> </div>
Step 2: Now We will create add,edit and delete function in controller.
$scope.edit = function(id) { //search user and update it $scope.objectIndex = id; $scope.userObject = angular.copy($scope.userList[id]); console.log($scope.objectIndex); } $scope.save = function() { console.log($scope.objectIndex); if($scope.userList[$scope.objectIndex] == null) { //this is new record $scope.userList.push($scope.userObject); } else { //for existing record //and update it. $scope.userList[$scope.objectIndex] = $scope.userObject; } //clear the add record form $scope.userObject = {}; $scope.objectIndex = ''; } $scope.delete = function(id) { //search record with given id and delete it for(i in $scope.userList) { if($scope.userList[i].id == id) { $scope.userList.splice(i,1); $scope.newcontact = {}; } } }
Step 3: Now we will call these method on click of icon on table list.
<div class="btn-group"> <button type="button" class="btn btn-default btn" ng-click="edit($index);"><i class="glyphicon glyphicon-pencil"></i></button> <button type="button" class="btn btn-default btn" ng-click="delete();"><i class="glyphicon glyphicon-trash"></i></button> </div>
I hope this help you.You can download source code and see Demo from below link.
This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More
in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More
This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More
We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More
in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More
I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More