title: can't 'ng-repeat' through javascript array in AngularJS, (by getting a JSON object from Django)
body: <p>This question is not Django related in any way because my Django view which returns a dummy JSON object works perfectly, just thought I would share the Django view which converts a 
  <code>Model.objects.all()</code> into pure JSON data then returns this pure data for an Angular controller to read and process through an ng-repeat:</p>
  
  <pre><code>from django.core import serializers
  from django.utils import simplejson
  
  def json(request):
  
      all_objects = list(Message.objects.all())
      to_json = serializers.serialize('json', all_objects)
  
      return HttpResponse(to_json, mimetype='application/json')
  </code></pre>
  
  <p>Now on to my question,
  I'm not sure if I'm having an Angular issue or pure JavaScript issue. I have an Angular controller called <code>testjson</code> which calls that Django view above which then successfully returns a JSON object like this:</p>
  
  <pre><code>[
     {
        "pk":1,
        "model":"chatfeed.message",
        "fields":{
           "body":"hey everyone",
           "chat_feed":"Dating",
           "likes":0,
           "author_obj":1,
           "parent_channel":1,
           "pub_date":"2014-03-18T23:29:27Z"
        }
     },
     {
        "pk":2,
        "model":"chatfeed.message",
        "fields":{
           "body":"How's it going?",
           "chat_feed":"Dating",
           "likes":0,
           "author_obj":1,
           "parent_channel":1,
           "pub_date":"2014-03-18T23:32:05Z"
        }
     },
     {
        "pk":3,
        "model":"chatfeed.message",
        "fields":{
           "body":"So what's going on right now",
           "chat_feed":"Events",
           "likes":0,
           "author_obj":1,
           "parent_channel":2,
           "pub_date":"2014-03-18T23:32:33Z"
        }
     },
     {
        "pk":4,
        "model":"chatfeed.message",
        "fields":{
           "body":"Going pretty well actually",
           "chat_feed":"Dating",
           "likes":0,
           "author_obj":1,
           "parent_channel":1,
           "pub_date":"2014-03-18T23:32:55Z"
        }
     }
  ]
  </code></pre>
  
  <p>And so I would just like to grab the body of a particular <code>chat_feed</code> to be printed in Angular JS using Angular's ng-repeat to get something like this if I wanted all chat messages from <code>chat_feed</code> "Dating":</p>
  
  <pre><code>&lt;div ng-controller="testjson" ng-click="getJSON()"&gt;
      &lt;ul ng-model="chatfeed"&gt;
          &lt;li ng-repeat="post in chatfeed"&gt;{$ post $}&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>So in order to get the ng-repeat to work, I believe. I would have to loop through the raw JSON object, grab the 'body' string from each index and store them into an array so that's what I did:</p>
  
  <pre><code>app.controller("testjson", function($scope, $http)
  {
          $scope.getJSON = function()
              {
  
                  var JSONObject = $http.get('http://domfa.de/testjson/').success(function(data)
                  {
                      $scope.totalfeed = data.length;
  
                      chatarray = new Array();
                      for (var i=0; i &lt; data.length; i++)
                      {
                          if (data[i].fields.chat_feed == $scope.currentFeed)
                          {
                              chatarray[i] = data[i].fields.chat_feed;        
                          }
                      }
  
                      console.log(chatarray);
                      $scope.chatfeed = chatarray;
  
                  }); 
  
              }
  });
  </code></pre>
  
  <p>So after all that, my console.log seems to be returning the proper array just fine with the <code>"body"</code>s from the correct <code>chat_feed</code>. <code>Console.log()</code> is doing what I want it to do and the array it prints is properly formatted with perfect syntax, but as for the HTML which calls the <code>ng-repeat="post in chatfeed"</code> angular function it doesn't seem to print anything at all unless I physically copy and past the array <code>console.log()</code> prints out and replace <code>ng-model="chatfeed"</code> with a hardcoded array the console.log() generates for me with no problems using <code>ng-init="['hows it going?', 'hey everyone']"</code>.</p>