title: Angular Cannot read property of null
body: <p>In a web app I have two box containing some elements. I also have an aside with filters (composed by a selection). At the beginning the filters are all selected, and it works. But when I try a combination which find nothing in the first list but there are some data in the second list, I got an error. This is the when I call the Service in the controller:</p>
  
  <pre><code>if(data){ // If i have some response form serve
  
   var tmp = null;
   var lastName = null;
  
   angular.forEach(data.people, function(ppl){
   if(ppl.lastName != lastName){
      if (lastName != null){
          $scope.people.push(tmp);
      }
      // Clean the tmp
      tmp = {
             name : null,
             count : 0,
             products : []
       };
       // Update lastName
       lastName = ppl.lastName;
    }
     // Add the actual row in the ob
     tmp.name = lastName;
     tmp.count += ppl.personCount;
     tmp.products.push(ppl);
    });
  
    // Process lasts elements (if there are some) in the array
    if(tmp.products.length &gt; 0){
      $scope.people.push(tmp);
    }
  </code></pre>
  
  <p>The error is: <code>Cannot read property 'products' of null</code></p>
  
  <p>I've tried to write:  <code>var tmp = [];</code> instead of null, but it says <code>Cannot read property 'products' of undefined</code></p>