JavaScript – Change Entry Using AngularJS

Java Free Projects


In this tutorial we will create a Change Entry Using AngularJS. This code will change the existing temporary data in the table when user click the update button. The code itself use a angular directives that can change the table row data in without the database storage. 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 https://getbootstrap.com/.

And, this is the link for the AngularJS https://angularjs.org/.

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. <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
  4. <link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
  5. <body ng-controller="myController">
  6. <nav class="navbar navbar-default">

  7. <div class="containet-fluid">
  8. <a class="navbar-brand" href="<a href="https://www.sourcecodester.com">Sourcecodester</a>
  9. " rel="nofollow">https://www.sourcecodester.com">Sourcecodester</a>
  10. </nav>

  11. <div class="col-md-6 well">
  12. <h3 class="text-primary">JavaScript - Change Entry Using AngularJS</h3>
  13. <hr style="border-top:1px dotted #ccc;"/>
  14. <form ng-submit="addEntry()">
  15. <input type="text" class="form-control" ng-model="newEntry.firstname" ng-required="true"/>
  16. <input type="text" class="form-control" ng-model="newEntry.lastname" ng-required="true"/>
  17. <input type="text" class="form-control" ng-model="newEntry.address" ng-required="true"/>
  18.  

  19. <table class="table table-bordered">
  20. <thead class="alert-info">
  21. <tr ng-repeat="member in members">
  22. <td>{{member.firstname}}</td>
  23. <td>{{member.lastname}}</td>
  24. <td>{{member.address}}</td>
  25. <td><button type="button" data-toggle="modal" data-target="#update_member" ng-click="selectMember(member)" class="btn btn-sm btn-warning"><span class = "glyphicon glyphicon-edit"></span> Update</button></td>
  26. <div class="modal fade" id="update_member" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  27. <div class="modal-dialog" role="document">
  28. <div class="modal-content">
  29. <div class="modal-header">
  30. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  31. <h4 class="modal-title text-info" id="myModalLabel">Updating Member</h4>
  32. <input type="text" class="form-control" ng-model="selectedMember.firstname"/>
  33. <input type="text" class="form-control" ng-model="selectedMember.lastname"/>
  34. <input type="text" class="form-control" ng-model="selectedMember.address"/>
  35. <div style="clear:both;"></div>
  36. <div class="modal-footer">
  37. <button class="btn btn-warning" data-dismiss="modal">Update</button>

Creating the Main Function

This code contains the main function of the application. This code will change a entry in table row 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){

  3.  

  4. $scope.newEntry = {};

  5. $scope.members = [];

  6.  

  7. $scope.addEntry = function(){

  8. $scope.members.push($scope.newEntry);

  9. $scope.newEntry = {};

  10. };

  11.  

  12. $scope.selectMember = function(member){

  13. $scope.selectedMember = member;

  14. };

  15. });

There you have it we successfully created a Change Entry 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!!





Source link

Leave a Reply

Your email address will not be published. Required fields are marked *