Skip to main content

JavaScript - Add Entry To Table Using AngularJS

In this tutorial we will create a Add Entry To Table Using AngularJS. This code will add a new entry to HTML table without databases when the user submit the form input. The code use angular directives that can add new entry as an array in order to store a temporary data without sending to the database server. This a user-friendly program feel free to modify and use it to your system.

We will be using AngularJS as a comprehensive JavaScript framework that extend the browser capabilities. It handles the heavy lifting of DOM manipulation and AJAX request in a whole.

Getting Started:

First you have to download Bootstrap, this is the link for the bootstrap that i used for the layout design

And, this is the link for the AngularJS

Creating The Interface

This is where we will create a simple form for our application. To create the forms simply copy and write it into you text editor, then save it index.html.

  1. <!DOCTYPE html>
  2. <html lang="en" ng-app="myModule">
  3. <head>
  4. <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
  5. <link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
  6. </head>
  7. <body ng-controller="myController">
  8. <nav class="navbar navbar-default">
  9. <div class="containet-fluid">
  10. <a class="navbar-brand" href="">Sourcecodester</a>
  11. </div>
  12. </nav>
  13. <div class="col-md-3"></div>
  14. <div class="col-md-6 well">
  15. <h3 class="text-primary">JavaScript - Add Entry To Table Using AngularJS</h3>
  16. <hr style="border-top:1px dotted #ccc;"/>
  17. <div class="col-md-4">
  18. <form>
  19. <div class = "form-group">
  20. <label>Firstname</label>
  21. <input type = "text" class = "form-control" ng-model = "newMember.firstname"/>
  22. </div>
  23. <div class = "form-group">
  24. <label>Lastname</label>
  25. <input type = "text" class = "form-control" ng-model = "newMember.lastname"/>
  26. </div>
  27. <div class = "form-group">
  28. <label>Address</label>
  29. <input type = "text" class = "form-control" ng-model = "newMember.address"/>
  30. </div>
  32. <center><button type="button" class="btn btn-primary" ng-click = "saveMember()"><span class = "glyphicon glyphicon-save"></span> Save</button></center>
  33. </form>
  34. </div>
  35. <div class="col-md-8">
  36. <table class="table table-bordered">
  37. <thead class="alert-info">
  38. <tr>
  39. <th>Firstname</th>
  40. <th>Lastname</th>
  41. <th>Address</th>
  42. </tr>
  43. </thead>
  44. <tr ng-repeat="member in members">
  45. <td>{{member.firstname}}</td>
  46. <td>{{member.lastname}}</td>
  47. <td>{{member.address}}</td>
  48. </tr>
  49. </tbody>
  50. </table>
  51. </div>
  52. </div>
  53. <div class="modal fade" id="update_member" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  54. <div class="modal-dialog" role="document">
  55. <div class="modal-content">
  56. <form>
  57. <div class="modal-header">
  58. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  59. <h4 class="modal-title text-info" id="myModalLabel">Updating Member</h4>
  60. </div>
  61. <div class="modal-body">
  62. <div class = "form-group">
  63. <label>Full Name</label>
  64. <input type = "text" class = "form-control" ng-model = ""/>
  65. </div>
  66. <div class = "form-group">
  67. <label>Address</label>
  68. <input type = "text" class = "form-control" ng-model = "selectedMember.address"/>
  69. </div>
  70. </div>
  71. <div class="modal-footer">
  72. <button class="btn btn-success" data-dismiss = "modal"><span class = "glyphicon glyphicon-edit"></span> Update</button>
  73. </div>
  74. </form>
  75. </div>
  76. </div>
  77. </div>
  78. <div class="modal fade" id="delete_member" aria-hidden="true">
  79. <div class="modal-dialog">
  80. <div class="modal-content">
  81. <form>
  82. <div class="modal-body">
  83. <center><h4 class="text-danger">Are you sure you want to delete this record?</h4></center>
  84. </div>
  85. <div class="modal-footer">
  86. <button class="btn btn-danger" data-dismiss="modal" ng-click="deleteMember()"><span class="glyphicon glyphicon-check"></span> Yes</button>
  87. <button class="btn btn-success" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> No</button>
  88. </div>
  89. </form>
  90. </div>
  91. </div>
  92. </div>
  93. </body>
  94. <script src="js/angular.js"></script>
  95. <script src="js/script.js"></script>
  96. <script src="js/jquery-3.2.1.min.js"></script>
  97. <script src="js/bootstrap.js"></script>
  98. </html>

Creating the Main Function

This code contains the main function of the application. This code will add new entry to table when the button is clicked. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js.

  1. var app = angular.module("myModule", [])
  2. .controller("myController", function($scope){
  4. $scope.newMember = {};
  5. $scope.clickedMembers = [];
  8. $scope.members = [];
  10. $scope.saveMember = function(){
  11. $scope.members.push($scope.newMember);
  12. $scope.newMember = {};
  13. };
  15. });

There you have it we successfully created a Add Entry To Table using AngularJS. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.


1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.