In this tutorial, we will create a Simple CRUD(update, delete) Operations Using AngularJS. In my last tutorial
Simple CRUD Operation Using AngularJS - Part 1 we already created a function that can create and read a data. This time we will try add some function that can update and delete the existing data. Before we proceed I hope that you read the previous tutorial and have already the code to continue on for what we left behind before. So coders let's start coding.
Creating a Form
In this form I just added a modal for update and delete
In the code above I just add some function to make the update and delete worked. The
ng-click = "selectMember(member)" will store the value of the indexing array in the table when clicked by the user.
ng-click = "deleteMember" will store the index of the targeted member when clicked.
Creating a function with AngularJS directives
This script will call a function within the angularJS directives.
var app = angular.module("myModule", [])
.controller("myController", function($scope){
$scope.newMember = {};
$scope.clickedMembers = [];
$scope.members = [
];
$scope.saveMember = function(){
$scope.members.push($scope.newMember);
$scope.newMember = {};
};
$scope.selectMember = function(member){
$scope.selectedMember = member;
};
$scope.updateMember = function(){
};
$scope.deleteMember = function(){
$scope.members.splice($scope.members.indexOf($scope.selectMember), 1);
};
});
The code above will process the request when clicked. The
$scope.selectMember will store the value of the selected member when clicked. The
$scope.deleteMember will delete the index of the targeted value when clicked.
There you have it we created a simple CRUD operation using AngularJS. I hope that this tutorial give you some insights about angularJS and help you to your on working projects. 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 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.