To add the JSON data to Table by using Angular JS.
https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"> Filter

  • Ascending Order
  • Descending Order
  • USER ID ID TITLE COMPLETED ACTION

                    <tbody>
                        <tr ng-repeat="x in userId">
                            <td>
                                <div ng-hide="editingData[x.id]">{{x.userId}}       </div>
                                <div ng-show="editingData[x.id]"><input   type="text" ng-model="x.userId" /></div>
                            </td>
                            <td>
                                <div>{{x.id}}</div>
    
                            </td>
                            <td>
                                <div ng-hide="editingData[x.id]">{{x.title}}   </div>
                                <div ng-show="editingData[x.id]"><input   type="text" ng-model="x.title" /></div>
                            </td>
                            <td>
                                <div ng-hide="editingData[x.id]">{{x.completed}} </div>
                                <div ng-show="editingData[x.id]"><input type="text" ng-model="x.completed" /></div>
                            </td>
                            <td>
                                <button ng-hide="editingData[x.id]" ng-  click="modify(x)">Modify</button>
                                <button ng-show="editingData[x.id]" ng-    click="update(x)">Update</button>
                                <button ng-hide="viewField">Remove</button>
                            </td>
                        </tr>
                    </tbody>
                </table>
     </div>
    <div>
    <div>ADD NEW DETALS</div>
    <form class="form-horizontal" role="form" ng-submit="addRow()">
    <div class="form-group">
        <label class="col-md-2 control-label">USER ID</label>
        <div class="col-md-4">
            <input type="text" class="form-control" name="userId"
                ng-model="x.userId" />
        </div>
     </div>
     <div class="form-group">
        <label class="col-md-2 control-label">ID</label>
        <div class="col-md-4">
            <input type="text" value=201 class="form-control" name="id"
                ng-model="x.id" />
        </div> </div>
    <div class="form-group">
        <label class="col-md-2 control-label">TITLE</label>
        <div class="col-md-4">
            <input type="text" class="form-control" name="title"
                ng-model="x.title" />
        </div>
    </div>
        <div class="form-group">
        <label class="col-md-2 control-label">COMPLETED</label>
        <div class="col-md-4">
            <input type="text" class="form-control" name="completed"
                ng-model="x.completed" />
        </div>
    </div>
    <div class="form-group">                                
        <div style="padding-left:110px">
            <input type="submit" value="Submit" class="btn btn-primary"/>
        </div>
    </div>
    </form>
    </div>
    </body>
    </html>
    

    Controllers.js

    var app = angular.module('myApp', []);
     app.controller('customersCtrl', function($scope, $http) {
     $scope.userId = [];
     $http.get("").success(function   (response) 
      {$scope.userId = response});
    
      $scope.editingData = [];
    
      for (var i = 1, length = $scope.userId.length; i < length; i++) {
      $scope.editingData[$scope.userId[i].id] = false;
      }
    
    
      $scope.modify = function(x){
        $scope.editingData[x.id] = true;
      };
    
    
       $scope.update = function(x){
        $scope.editingData[x.id] = false;
       };
    
    
       });
    
    
      $scope.addRow =function( event ){
      if (event.success) {
      $http.post("", {     'userId':$scope.userId, 'id': $scope.id,  'title':$scope.title, 'completed':$scope.completed })
      .success(function (response) 
      {$scope.userId = response;
      });
       }
       }
    

    Style.css

    body {
    

    background-color: #eef;
    } #tabs { width: 95%; margin-left: auto; margin-right: auto; margin-top: 10px;

     }
    
      table, th , td {
     border: 1px solid grey;
     border-collapse: collapse;
      padding: 4px;
      font-family: arial;
    
      }
    
      td {
    text-align: center;
      }
    
     th {
     background: darkblue;
     color: white;
     text-align: center;
       }
       /*Style for Alternate Rows*/
       table tr:nth-child(odd) {
        background-color: #C2EBC3;
        }
        table tr:nth-child(even) {
        background-color: #FFFFFF;
        }
    

    Simple example

      <!DOCTYPE html>
      <html>
       <head>
        <script src=     "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
       </head>
    
    
      <body ng-app="MyApp">
        <input type="text" ng-model="text" placeholder="Enter text"/>
         <p>Input: {{ text }}</p>
         <p>Filtered input: {{ text | reverse }}</p>
    
    
    
              <my-directive></my-directive>
    
          <script type="text/javascript">
          app.angular.module('myApp', [])
         .directive('myDirective', function() {
        return {
          restrict: 'E',
           template: '<a href="http://google.com">
         Click me to go to Google</a>'
           }
          });
    
    
          var app = angular.module("MyApp", []);
    
         app.filter("reverse", function() {
        return function(input) {
       var result = "";
        input = input || "";
       for (var i=0; i<input.length; i++) {
      result = input.charAt(i) + result;
       }
         return result;
        };
       });
       </script>
       </body>
       </html>
    

    For reference you can use this links


    "http://www.revillweb.com/tutorials/angularjs-in-30-minutes-angularjs-tutorial/" "Push json data to existing array in angular js" "Adding new row of fields with AngularJS ng-repeat"

    "Angularjs - Update JSON"

    share|improve this question

    You need to define your app only once. you need to remove this line var app = angular.module("MyApp"); which is flushing your app which has myDirective directive.

    Code

    app.angular.module('myApp', [])
    .directive('myDirective', function() {
      return {
        restrict: 'E',
        template: '<a href="http://google.com">
        Click me to go to Google < /a>'
      }
    });
    app.filter("reverse", function() {
      return function(input) {
        var result = "";
        input = input || "";
        for (var i = 0; i < input.length; i++) {
          result = input.charAt(i) + result;
        }
        return result;
      };
    });
    
    share|improve this answer

    Your Answer

     
    discard

    By posting your answer, you agree to the privacy policy and terms of service.

    Not the answer you're looking for? Browse other questions tagged or ask your own question.