title: AngularJS - Using Nested JSON Objects in Sum of NG-Repeat totals
body: <p>I have adapted some code from an answer to a similar question I found searching here. Can someone please point me in the right direction on how to fix this code...</p>
  
  <p>I am trying to to sum the values of a filtered column in ng-repeat. It works great for the first level of nested JSON but will not work on the second level.. </p>
  
  <p>The JSON provided is just an example..The real JSON is coming from a source that I have no control over the structure of the JSON itself.</p>
  
  <p>My code is below..Help Please!!!</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>       
  
  angular.module("turfApp", [])
              .filter('sumOfValue', function () {
                  return function (data, key) {
                      debugger;
                      if (angular.isUndefined(data) || angular.isUndefined(key))
                          return 0;
                      var sum = 0;
  
                      angular.forEach(data, function (v,k) {
                          sum = sum + parseInt(v[key]);
                      });
                      return sum;
                  }
              }).controller("turfController", function ($scope) {
                  $scope.items = [{
                      "id": { "t": 1 }, //NESTED "T" VALUE WILL NOT COMPUTE IN TOTALS
                      "details": "test11",
                      "quantity": 2,
                      "price": 100
                  }, {
                      "id": { "t": 2 }, //NESTED "T" VALUE WILL NOT COMPUTE IN TOTALS
                      "details": "test12",
                      "quantity": 5,
                      "price": 120
                  }, {
                      "id": { "t": 3 }, //NESTED "T" VALUE WILL NOT COMPUTE IN TOTALS
                      "details": "test3",
                      "quantity": 6,
                      "price": 170
                  }, {
                      "id": { "t": 4 }, //NESTED "T" VALUE WILL NOT COMPUTE IN TOTALS
                      "details": "test3",
                      "quantity": 8,
                      "price": 70
                  }, {
                      "id": { "t": 5 }, //NESTED "T" VALUE WILL NOT COMPUTE IN TOTALS
                      "details": "test5",
                      "quantity": 2,
                      "price": 160
                  }, {
                      "id": { "t": 6 }, //NESTED "T" VALUE WILL NOT COMPUTE IN TOTALS
                      "details": "test6",
                      "quantity": 9,
                      "price": 100
                  }]
              });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>  &lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"&gt;&lt;/script&gt;   
  
  &lt;div ng-app="turfApp" ng-controller="turfController"&gt;
          &lt;input type="text" class="form-control" ng-model="searchFilter.id.t" placeholder="Search by ID" /&gt;
          &lt;table&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th&gt;Id&lt;/th&gt;
                      &lt;th&gt;Details&lt;/th&gt;
                      &lt;th&gt;Quantity&lt;/th&gt;
                      &lt;th&gt;Price&lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
                  &lt;tr ng-repeat="item in resultValue=(items | filter:searchFilter)"&gt;
                      &lt;td&gt;&lt;p&gt;{{item.id.t}}&lt;/p&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;p&gt;{{item.details}}&lt;/p&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;p&gt;{{item.quantity}}&lt;/p&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;p&gt;{{item.price}}&lt;/p&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;p&gt;{{item.quantity * item.price}}&lt;/p&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/tbody&gt;
          &lt;/table&gt;
  
          &lt;div&gt;
              &lt;h4&gt;Sum ID -- {{resultValue | sumOfValue:'id.t'}}&lt;/h4&gt;
          &lt;/div&gt;
          &lt;div&gt;
              &lt;h4&gt;Sum Quanitity -- {{resultValue | sumOfValue:'quantity'}}&lt;/h4&gt;
          &lt;/div&gt;
      &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>