title: AngularJS Editable Table
body: <p>I want to create a editable table in AngularJs. Same date I am using for another list and details view in same page.</p>
  
  <p>My query is when I click the  edit link in the list details view (Selected View Section in the page) part and modify the values in the textbox it is not changing in the table view section until I click the save button, but when I click the edit in the table section (Editable Table section in the page) part and modify the value in the textbox is it changing in the Selected View section also. </p>
  
  <p>But, I want the change the all the values after I click the save link. Please fine the sample code and advise me.</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html lang="en" ng-app="myApp"&gt;
  &lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;title&gt;Example - example-example53-production&lt;/title&gt;
    &lt;script src="js/angular.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body ng-controller="MainCtrl"&gt;
  
  
  &lt;h1&gt;Editable Table&lt;/h1&gt;
    &lt;table id="searchObjResults"&gt;
      &lt;tr&gt;&lt;th ng-click="sort('name')"&gt;Name&lt;/th&gt;&lt;th ng-click="sort('phone')"&gt;Phone&lt;/th&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;&lt;input ng-model="search.name"&gt;&lt;/td&gt;&lt;td&gt;&lt;input ng-model="search.phone"&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr ng-repeat="friendObj in users | orderBy:orderProp:direction| filter:search:strict" ng-class-odd="'odd'"&gt;
  
        &lt;td click-to-edit="friendObj" type="tbl"&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
  
  
    &lt;h1&gt;Selected View&lt;/h1&gt;
    &lt;ul&gt;
      &lt;li ng-repeat="user in users" ng-class="{active: checkActive(user)}" ng:click="select(user)"&gt;{{user.name}}&lt;/li&gt;
    &lt;/ul&gt;
    &lt;p&gt;selected: {{selectedUser.phone}}&lt;/p&gt;
    &lt;p click-to-edit="selectedUser.name"&gt;&lt;/p&gt;
    &lt;p click-to-edit="selectedUser.phone"&gt;&lt;/p&gt;
    &lt;script&gt;
  
    var myApp = angular.module('myApp', []);
      //myApp.by.id('setbtn')element('h1').addClass('active');
  
      myApp.controller('MainCtrl', ['$scope','$filter', function ($scope,$filter) {
  
      $scope.users = [{name:'John', phone:'555-1276'},
                      {name:'John', phone:'555-1278'},
                      {name:'Mary', phone:'800-BIG-MARY'},
                      {name:'Mike', phone:'555-4321'},
                      {name:'Adam', phone:'555-5678'},
                      {name:'Julie', phone:'555-8765'},
                      {name:'Juliette', phone:'555-5678'}];
  
      //setting for order
      $scope.users = $filter('orderBy')($scope.users, 'name');
  
      //to set the defalult search
          //$scope.search = {
              //phone : "555-1278"
          //};
      //sorting
          $scope.direction = false;
          $scope.orderProp = "name";
          $scope.sort = function(column) {
              if ($scope.orderProp === column) {
                  $scope.direction = !$scope.direction;
              } else {
                  $scope.orderProp = column;
                  $scope.direction = false;
              }
          };
          //selected when list click
           $scope.select = function(user) {
              $scope.selectedUser = user;
           };
          //applying the selected Class
          $scope.checkActive = function(user) {
              return $scope.selectedUser == user;
          };
          //set the first item as selected
          //$scope.select($scope.users[0]);
          $scope.selectedUser = $scope.users[0];
  
  
  }]);
  myApp.directive("clickToEdit", function() {
    var editorTemplate = '&lt;td class="click-to-edit"&gt;' +
          '&lt;div ng-hide="view.editorEnabled"&gt;' +
              '{{value.name}} ' +
              '{{value.phone}} ' +
              '&lt;a href="#" ng-click="enableEditor()"&gt;Edit&lt;/a&gt;' +
          '&lt;/div&gt;' +
          '&lt;div ng-show="view.editorEnabled"&gt;' +
              '&lt;input ng-model="view.editableValue.name"&gt;' +
               '&lt;input ng-model="view.editableValue.phone"&gt;' +
              '&lt;a href="#" ng-click="save()"&gt;Save&lt;/a&gt;' +
              ' or ' +
              '&lt;a href="#" ng-click="disableEditor()"&gt;cancel&lt;/a&gt;.' +
          '&lt;/div&gt;' +
      '&lt;/td&gt;';
       var editorTemplate1 = '&lt;div class="click-to-edit"&gt;' +
          '&lt;div ng-hide="view.editorEnabled"&gt;' +
              '{{value}} ' +
              '&lt;a href="#" ng-click="enableEditor()"&gt;Edit&lt;/a&gt;' +
          '&lt;/div&gt;' +
          '&lt;div ng-show="view.editorEnabled"&gt;' +
              '&lt;input ng-model="view.editableValue"&gt;' +
              '&lt;a href="#" ng-click="save()"&gt;Save&lt;/a&gt;' +
              ' or ' +
              '&lt;a href="#" ng-click="disableEditor()"&gt;cancel&lt;/a&gt;.' +
          '&lt;/div&gt;' +
      '&lt;/div&gt;';
  
      return {
          restrict: "A",
          replace: true,
          //template: editorTemplate,
          template: function(element, attrs) {
            if(attrs.type=='tbl'){
              return editorTemplate;
            }
            else{
            return editorTemplate1;
            }
          },
          scope: {
              value: "=clickToEdit",
          },
           link: function(scope, element, attrs) {
            //alert(element);
          },
          controller: function($scope) {
              $scope.view = {
                  editableValue: $scope.value,
                  editorEnabled: false
              };
  
              $scope.enableEditor = function() {
                  $scope.view.editorEnabled = true;
                  $scope.view.editableValue = $scope.value;
              };
  
              $scope.disableEditor = function() {
                  $scope.view.editorEnabled = false;
              };
  
              $scope.save = function() {
                  $scope.value = $scope.view.editableValue;
                  $scope.disableEditor();
              };
          }
      };
  });
  
  
  
    &lt;/script&gt;
    &lt;style&gt;
    .active{color:green}
    &lt;/style&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>