Simple CRUD Operation Using AngularJS - Part 1
Submitted by razormist on Friday, February 3, 2017 - 14:41.
Language
In this tutorial, we will create a Simple CRUD(create, read) Operations Using AngularJS. AngularJS is a structural framework for dynamic web apps. It is a kind of template that extends HTML to a new level of coding techniques. This time we will try to see how angularjs can create a simple CRUD operation. By the way this tutorial is consist of two parts. The one we will be doing now is on how to create and read a data. So let get started.
Creating A Form
This is where the data manipulation will happened. To do that open any kind of text editor(notepad++, etc), then copy/paste the code below and name it "index.html"
The code above will display the value that been input in the textbox. The ng-click will trigger the function when clicked and processed the statement that have been assigned to generate the result. The ng-repeat will loop and display all the data that been stored.
Setting Up The AngularJS Directive Script
This script will take responsibility for implementing the directives into the HTML forms. To create this script, just kindly copy/paste the code below and name it "app.js"
The code above above will generate the request when the $scope.saveMember been clicked by the user and stored it into the $scope.members = []; array to be display in the HTML form.
There you have it, we created a simple CRUD create and read operation. I hope that this tutorial help you to your developing projects. For the next tutorial we will tackle about CRUD update and delete operation, so just stay tuned and kindly visit this site. Enjoy Coding!!
- <!DOCTYPE html>
- <html lang = "en">
- <head>
- <meta charset = "UTF-8" name = "viewport" content = "width=device-width, initial-scale=1"/>
- <link rel = "stylesheet" type = "text/css" href = "css/bootstrap.css" />
- </head>
- <body ng-app = "myModule" ng-controller = "myController">
- <nav class = "navbar navbar-default">
- <div class = "containet-fluid">
- </div>
- </nav>
- <div class = "row">
- <div class = "col-md-8 well">
- <hr style = "border-top:1px dotted #000;"/>
- <div class = "container-fluid">
- <br />
- <br />
- <table class = "table table-bordered alert-warning">
- <thead>
- <tr>
- </tr>
- </thead>
- <tbody>
- <tr ng-repeat = "member in members">
- </tr>
- </tbody>
- </table>
- </div>
- </div>
- </div>
- <div class="modal fade" id="add_member" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
- <div class="modal-dialog" role="document">
- <div class="modal-content">
- <form>
- <div class="modal-header">
- </div>
- <div class="modal-body">
- <div class = "form-group">
- <input type = "text" class = "form-control" ng-model = "newMember.name"/>
- </div>
- <div class = "form-group">
- <input type = "email" class = "form-control" ng-model = "newMember.email"/>
- </div>
- <div class = "form-group">
- <select class = "form-control" ng-model = "newMember.gender" >
- </select>
- </div>
- </div>
- <div class="modal-footer">
- </div>
- </form>
- </div>
- </div>
- </div>
- </body>
- </html>
- var app = angular.module("myModule", [])
- .controller("myController", function($scope){
- $scope.newMember = {};
- $scope.members = [];
- $scope.saveMember = function(){
- $scope.members.push($scope.newMember);
- $scope.newMember = {};
- };
- });
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 SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
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
- 328 views