Introduction
Inline editing is the tool we often need in nearly all of our applications. These days with modern web technologies no one wants multiple pages for displaying and editing contents, like earlier we had viewprofile and editprofile pages. It gives an amazing user experience when the user wants to edit some content and upon his click the display content instantly changes to an editable one and it can be saved and refreshed instantly without going to another page.
This tutorial explains the creation of an inline editing system using AngularJs. Here I assume you have the basic knowledge of AngularJs.
Basic Idea
Let's have a basic idea of what we will do first.
Every time the content is loaded I will check if it is set to be displayed or edited and on the basis of this value I will call my script that contains nothing but the HTML for display and edit respectively.
Example
Let us see an example that will help us understand the situation better.
I have an array of customers, we will list them in a table using ng-repeat and then add some functions for the inline editing functionality.
Code
Let us first display all the customers using ng-repeat.
- <table class="table table-striped table-bordered">
- <thead>
- <th>Employee Name</th>
- <th>Employee Email</th>
- <th>Employee Salary</th>
- <th>Active</th>
- <th>Edit</th>
- </thead>
- <tbody>
- <tr ng-repeat="employee in employees">
- <td>{{employee.empName}}</td>
- <td>{{employee.empEmail}}</td>
- <td>{{employee.empSalary | currency:"₹"}}</td>
- <td>{{employee.active | active}}</td>
- <td>
- <button type="button" class="btn btn-primary">Edit</button>
- <button type="button" class="btn btn-danger">Delete</button>
- </td>
- </tr>
- </tbody>
- <table>
Here employees is an array of employee data and we are iterating each employee using ng-repeat directive. This is a simple use of ng-repeat, we will modify it depending on our needs to build an in-line editing system, but first let's have a look at how it looks.
Table using ng-repeat
Here I have two buttons, edit and delete. The delete button will simply delete the entry from the database using a HTTP request. Our main focus here is on the edit button that will turn this display mode onto an editing mode. Let us proceed and make some changes to the code to make it functional.
The first change we will make is to add a ng-include directive that will call a function getTemplate() and this function will take a parameter that is nothing but a single employee from the employees array.
- <tr ng-repeat="employee in employees" ng-include="getTemplate(employee)">
getTemplate() is very simple and will check if the employee passed in the parameter is set to be displayed or editeed and accordingly we will call a script of the HTML content.
- $scope.getTemplate = function (employee) {
- if (employee.empID === $scope.selected.empID){
- return 'edit';
- }
- else return 'display';
- };
As you can see, the preceding code is very simple. The thing that might confuse you is the if condition here. Let me make it more clear here; employee is the value passed as a parameter and $scope.selected is a JSON object that will hold the employee data upon being selected to edit and is initially set to null.




ARITRO MUKHERJEEPosted Sep 15, 2017, 4:08 AM
Is it the actual Code....It looks like a different code attached
Jithil JohnPosted Jan 25, 2016, 5:08 AM
Good one
Prashant KoliPosted Jan 5, 2016, 10:16 AM
I'm unable to get the ng-include src as it's being considered as a new route.
RakeshPosted Jul 20, 2015, 11:44 PM
Good one
Chervine BhiwooPosted Jul 17, 2015, 3:10 PM
That's cool! Thanks for sharing
Sourabh SomaniPosted Jul 17, 2015, 12:01 PM
Nice One Bro :)
Bala DeenadayalanPosted Jul 17, 2015, 1:41 AM
Nice article.Add downloadable code too.
Moris JPosted Jul 17, 2015, 12:10 AM
good effort
Santhakumar MunuswamyPosted Jul 16, 2015, 3:59 PM
Nice Article! Thanks for sharing
Gopi ChandPosted Jul 15, 2015, 12:35 PM
Good one sir
Sathish KumarPosted Jul 15, 2015, 7:30 AM
Good sharing
Nilesh JadavPosted Jul 15, 2015, 6:32 AM
Nice one sir
Manish Kumar ChoudharyPosted Jul 15, 2015, 5:31 AM
Nice one.
Sibeesh VenuPosted Jul 15, 2015, 5:31 AM
Nice Share Thank you :)