AngularJS taking JSON from nodejs API
<p>I got some kind of strange question.
My nodejs api works with mongodb.
Angular is requesting data from nodejs by JSON.
I use Webstorm 11 to launch Angular App.
So, then I'm doing <strong>ng-repeat</strong> using that JSON and get this:</p>

<pre><code>    TypeError: Cannot read property '$id' of undefined
    at arguments.(anonymous function) (chrome-extension://ighdmehidhipcmcojjgiloacoafjmpfk/dist/hint.js:2001:19)
    at m.$digest (https://code.angularjs.org/1.5.0/angular.min.js:138:399)
    at m.scopePrototype.$digest (chrome-extension://ighdmehidhipcmcojjgiloacoafjmpfk/dist/hint.js:2016:23)
    at m.$apply (https://code.angularjs.org/1.5.0/angular.min.js:141:341)
    at m.scopePrototype.$apply (chrome-extension://ighdmehidhipcmcojjgiloacoafjmpfk/dist/hint.js:2079:22)
    at https://code.angularjs.org/1.5.0/angular.min.js:21:44
        at Object.invoke (https://code.angularjs.org/1.5.0/angular.min.js:41:295)
    at Ac.c (https://code.angularjs.org/1.5.0/angular.min.js:20:468)
    at Object.Ac.ia.resumeBootstrap (https://code.angularjs.org/1.5.0/angular.min.js:21:357)
    at maybeBootstrap (chrome-extension://ighdmehidhipcmcojjgiloacoafjmpfk/dist/hint.js:569:11)
</code></pre>

<p>and this:</p>

<pre><code>    TypeError: Cannot read property '$id' of undefined
    at arguments.(anonymous function) (chrome-extension://ighdmehidhipcmcojjgiloacoafjmpfk/dist/hint.js:2001:19)
    at m.$digest (https://code.angularjs.org/1.5.0/angular.min.js:138:399)
    at m.scopePrototype.$digest (chrome-extension://ighdmehidhipcmcojjgiloacoafjmpfk/dist/hint.js:2016:23)
    at m.$apply (https://code.angularjs.org/1.5.0/angular.min.js:141:341)
    at m.scopePrototype.$apply (chrome-extension://ighdmehidhipcmcojjgiloacoafjmpfk/dist/hint.js:2079:22)
    at g (https://code.angularjs.org/1.5.0/angular.min.js:94:139)
    at t (https://code.angularjs.org/1.5.0/angular.min.js:98:260)
    at XMLHttpRequest.u.onload (https://code.angularjs.org/1.5.0/angular.min.js:99:297)
</code></pre>

<p>for every element in ng-repeat.
Result page works fine, but this errors in console are not good.</p>

<p>Then I tried to use this JSON:
<a href="https://s3.amazonaws.com/codecademy-content/courses/ltp4/forecast-api/forecast.json" rel="nofollow">https://s3.amazonaws.com/codecademy-content/courses/ltp4/forecast-api/forecast.json</a></p>

<p>Working with this JSON not throwing any errors..
So thats how I realize that my JSON not "good enough" :D Maybe I need to put some kind of headers? In attached pictures you can compare JSON's that I'm using.</p>

<p>p.s. One more strange thing: when i'm executing my index.html file in browser without webstorm (file:///Users/rustem/Dropbox/octomoney/index.html) - no errors occur in console and the app works fine!</p>

<p><strong>JSON's</strong>:</p>

<pre><code>    curl -i -X GET http://localhost:3000/getData?collection=expenses
    HTTP/1.1 200 OK
    X-Powered-By: Express
    Access-Control-Allow-Origin: *
    Content-Encoding: UTF-8
    Content-Type: application/json; charset=utf-8
    Content-Length: 1009
    ETag: W/"3f1-Y7uhK30COBeAh0OJQ4Upzg"
    Date: Fri, 19 Feb 2016 12:49:25 GMT
    Connection: keep-alive

    {"result":"1","message":"Request completed","data":[{"name":"Прочее","icon":"all_inclusive","color":"#b7cfd9","subCategories":"Ebay &amp; Ali"},{"name":"Автомобиль","icon":"directions_car","color":"#63a3d2","subCategories":"Ремонт"}]}


    curl -i -X GET https://s3.amazonaws.com/codecademy-content/courses/ltp4/forecast-api/forecast.json
    HTTP/1.1 200 OK
    x-amz-id-2: I2wao57Or1Ib/0Ox9Bp/g5xNrlqqxbK/7kti+YjugN3974z1soOeOMhH+e5mw2Pz
    x-amz-request-id: 7B8334962BA70A53
    Date: Fri, 19 Feb 2016 12:44:56 GMT
    Expires: 0
    Content-Encoding: UTF-8
    Cache-Control: no-cache
    Last-Modified: Mon, 26 Jan 2015 16:20:44 GMT
    ETag: "f059fbba22678ca58a51d7b8d1e99061"
    Accept-Ranges: bytes
    Content-Type: application/json
    Content-Length: 946
    Server: AmazonS3

    {
    "city_name": "New York",
    "country": "US",
    "days": [
    {
    "datetime": 1420390800000,
    "icon": "https://s3.amazonaws.com/codecademy-content/courses/ltp4/forecast-api/sun.svg",
    "high": 68,
    "low": 37
    },
    {
    "datetime": 1420736400000,
    "icon": "https://s3.amazonaws.com/codecademy-content/courses/ltp4/forecast-api/sun.svg",
    "high": 59,
    "low": 32
    }
</code></pre>

<p>how I use <strong>ng-repeat:</strong></p>

<pre><code>    &lt;body ng-app="octomoney"&gt;
    &lt;div&gt;
        &lt;div ng-controller="getExpensesController"&gt;
            &lt;div ng-repeat="expense in expenses.data" align="center"&gt;
                &lt;h4&gt;{{ expense.name }}&lt;/h4&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;

    &lt;script src="https://code.angularjs.org/1.5.0/angular.min.js"&gt;&lt;/script&gt;
    &lt;script src="js/app.js"&gt;&lt;/script&gt;
    &lt;script src="js/controllers/mainController.js"&gt;&lt;/script&gt;
    &lt;script src="js/services/getExpensesService.js"&gt;&lt;/script&gt;
    &lt;/body&gt;
</code></pre>

<p><strong>app.js</strong>:</p>

<pre><code>    var app = angular.module('octomoney', []);
</code></pre>

<p><strong>mainController.js</strong>:</p>

<pre><code>    app.controller('getExpensesController', ['$scope', 'getExpensesService', function ($scope, getExpensesService) {
        getExpensesService.success(function (data) {
            $scope.expenses = data;
        });
    }]);
</code></pre>

<p><strong>getExpensesService.js</strong>:</p>

<pre><code>    app.factory('getExpensesService', ['$http', function ($http) {
        //return $http.get('https://s3.amazonaws.com/codecademy-content/courses/ltp4/forecast-api/forecast.json')
            return $http.get('http://localhost:3000/getData?collection=expenses&amp;queryBuilder=1==1')
            .success(function (data) {
                return data;
            })
            .error(function (err) {
                return err;
            });
    }]);
</code></pre>