title: AngularJS Push New Data into Specific JSON
body: <p>I've got a JSON output that looks like this:</p>
  
  <pre><code>[{"id":"121","title":"Blog Title","content":"Blog content"}, "comments":[{"id":"12","content":"This is the comment."}]]
  </code></pre>
  
  <p>I'm retrieving the array through a controller in Angular:</p>
  
  <pre><code>app.controller('BlogController', function($scope, $http) {
      var blog = this;
      blog.posts = [];
  
      $http.get('/process/getPost.php').success(function (data) {
          blog.posts=data;
      });
  
      $scope.submitComment = function() {
  
          blog.posts.concat($scope.formData);
  
          $http({
              method  : 'POST',
              url     : '/process/insertComment.php',
              data    : $.param($scope.formData),  // pass in data as strings
              headers: {'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'}
          })
          .success(function(data) {
              console.log(data);
              $scope.formData.comment="";
          });
      };
  })
  </code></pre>
  
  <p>Then displaying the information in my index.html file:</p>
  
  <pre><code>&lt;div ng-controller="BlogController as blog" ng-cloak class='ng-cloak'&gt;
      &lt;div ng-repeat="post in posts"&gt;
          &lt;div&gt;{{post.title}}&lt;/div&gt;
          &lt;div&gt;{{post.content}}&lt;/div&gt;
      &lt;/div&gt;
      &lt;div ng-repeat="comment in post.comments"&gt;
          {{comment.content}}
      &lt;/div&gt;
      &lt;form name="commentform" ng-init="formData.id=post.id" novalidate&gt;
          &lt;textarea ng-model="formData.comment" name="comment" required&gt;&lt;/textarea&gt;&lt;br&gt;
          &lt;input type="submit" ng-disabled="commentform.$invalid" value="Submit" ng-click="submitComment()"&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Everything works as it should but I've been trying to have the submitComment() update comment.content inside JSON array where the blog id equals post.id and where the comment id equals comment.id.</p>
  
  <p>I've tried doing blog.post.comment.push($scope.formData) but that didn't work.  Any idea why it doesn't work and how to fix it?</p>