how to dynamically Add and Delete rows dynamically using angularjs?

Today, We want to share with you add and delete rows dynamically using angularjs.In this post we will show you add/remove input fields dynamically with angularjs, hear for Angularjs create table with add/delete row, from ng-repeat in object of objects we will give you demo and example for implement.In this post, we will learn about Add or Remove Table Rows Dynamically in AngularJS with an example.

add, edit delete table row using angularjs



<body ng-app="myapp" ng-controller="ListController">     
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <form ng-submit="addNew()">
                            <table class="table table-striped table-bordered">
                                        <th><input type="checkbox" ng-model="selectedAll" ng-click="checkAll()" /></th>
                                        <th>Customer Firstname</th>
                                        <th>Customer Lastname</th>
                                        <th>Customer Email</th>
                                    <tr ng-repeat="customerDetail in customerDetails">
                                            <input type="checkbox" ng-model="customerDetail.selected"/></td>
                                            <input type="text" class="form-control" ng-model="customerDetail.firstnm" required/></td>
                                            <input type="text" class="form-control" ng-model="customerDetail.lastnm" required/></td>
                                            <input type="email" class="form-control" ng-model="" required/></td>

                            <div class="form-group">
                                <input ng-hide="!customerDetails.length" type="button" class="btn btn-danger pull-right" ng-click="remove()" value="Remove">
                                <input type="submit" class="btn btn-primary addnew pull-right" value="Add New">

Angularjs Code


var app = angular.module("myapp", []);
app.controller("ListController", ['$scope', function($scope) {
    $scope.customerDetails = [
            'email':'[email protected]'
            'email':'[email protected]'
            'email':'[email protected]'
        $scope.addNew = function(customerDetail){
                'firstnm': "", 
                'lastnm': "",
                'email': "",
        $scope.remove = function(){
            var newDataList=[];
            $scope.selectedAll = false;
            angular.forEach($scope.customerDetails, function(selected){
            $scope.customerDetails = newDataList;
    $scope.checkAll = function () {
        if (!$scope.selectedAll) {
            $scope.selectedAll = true;
        } else {
            $scope.selectedAll = false;
        angular.forEach($scope.customerDetails, function(customerDetail) {
            customerDetail.selected = $scope.selectedAll;

CSS code


    margin-right: 10px;
  margin: 20px 0;

Demo with Source code Add/Delete rows in table dynamically using Angular

Read Also:  Group By with Count using Laravel Collection

I hope you get an idea about Add/Delete rows in table dynamically.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Nested Queries Subqueries in SQL Example
  2. Read Also:  Add custom text to image in Laravel with Example
  3. Read Also:  Group By Preserve Key using Laravel Collection
  4. Read Also:  AngularJS Adding Form Fields Dynamically with PHP MySQLi
  5. Read Also:  Add or Remove Table Rows Dynamically in AngularJS
  6. Read Also:  How to add Bootstrap Tooltip Plugin Example
  7. Read Also:  Group By with Multiple Columns using Laravel Collection
  8. Read Also:  Get Radio Button value using AngularJS
  9. Read Also:  Group By with Date using Laravel Collection
  10. Read Also:  Laravel Get Route Parameters in middleware Example