As you all know Angularjs is getting popularity day by day, because of its data binding and dependency injection to reduce code, otherwise we need to write lot of code, client side framework, easy to integrate with any language which makes in top position. In previous discussion we had worked on ng-route model.
Now we will discuss how to update form using Angularjs and codeigniter, before going to concept you all need to know about Factory provider, which will adds below abilities.

  • We can use other services(which have dependencies).
  • We can initialize the service.
  • Delayed and Lazy initialization can be done using Factor recipe.

Now I will use factory recipe in our update form functionality, let’s create app.js file

var welcome = angular.module('welcome', ['ngRoute']);
            $scope.current = data;
$scope.editUser= function(current){
            //route.reload refreshes the contents of the current page without updating
           // alert(data);
                $scope.response='updated record successfully';
                 $scope.response='Failed to updated record';
        getUser : function(id)
          return $http({
           url: 'http://localhost:81/Codeigniter/index.php/welcome/getUser/'+id,
           method: 'GET'
        updateUser : function(current)
            return $http({
                data :"user_id="+current.user_id+"&firstname="+current.firstname+"&lastname="+current.lastname+"&emailid="+current.emailid+"&City="+current.City+"&phone=""&address="+current.address,
                headers : {'Content-Type': 'application/x-www-form-urlencoded'}

Don’t be panic seeing the above angular code, which is easy to understand, let’s check the code now.
Here we create update controller in our app.js file, I had used dependency injection concept by calling factory service in update Controller.
In the factory recipe I used two functions to get the data which need to be updated and used post method to update the record, now I called these two functions in update controller.
Now let’s create form_edit.html in angular_pages folder as we discussed in previous article.

Now look at codeigniter controller functions below.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

	public $data;
 	public function __construct()
	{//Core controller constructor

public function getUser($user_id)
    echo json_encode($this->ektreemodel->getuserdetails($user_id));
public function updateUser()
                    echo json_encode(array("response" => "success"));
                    echo json_encode(array("response" => "failedProcess"));



Now let’s check model function how to update a record using below code.


class Ektreemodel extends CI_Model
public function getuserdetails($user_id)

  return $query->row();
 public function updaterecord()
    $data = array(
    		"firstname" =>$firstname,
    		"lastname"  =>$lasttname,
                "emailid"   =>$emailid,
    		"City"   =>$City,
    	return $this->db->update("registration", $data);


Now we are at last step, while clicking the edit link we need to pass user_id to the angular controller, I am adding the single line of code, which needs to be placed in users_list.html and also update route config as below.

.when("/edit/:id", {

This file is already created in previous article, Please go through the complete article.

 <td><a href="#/edit/{{item.user_id}}"><span class="glyphicon glyphicon-pencil"></span></a></td>

Thanks for reading this article ,for any queries please use comment section. Subscribe to eknowledgetree for new and latest classes.