title: Cannot find property 'filter' of undefined
body: <p>I have set up my online shop project (Angular) and been trying to do some sort of "Recommendations" area in each product page.</p>
  
  <p>At first I wanted to subscrible all of my products, and then going over them in order to find matching type and id.</p>
  
  <p>Just for testing, I've created 18 products(6 different products) in my MongoDB (3 products of the same product with the same type and id), but unfortunately received this error and cannot figure out why:</p>
  
  <p><strong>Cannot read property 'filter' of undefined
      at ProductComponent.findRecommandedProducts</strong></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>export class ProductComponent implements OnInit {
  
    recommandedProducts: Product[];
    allProducts: Product[];
    product: Product;
  
  
    constructor(private productService: ProductService, private route: Router, private actRoute: ActivatedRoute) { }
  
    ngOnInit() {
      this.recommandedProducts = this.findRecommandedProducts(this.product)
    };
  
    findRecommandedProducts(currectProduct: Product){
      this.productService.getProducts().subscribe((data: Product[]) =&gt; {
        this.allProducts = data;
      });
  //productService.getProducts() returns all of my products in JSON format to localhost//
  
      let recommandedProducts = this.allProducts.filter(otherProduct =&gt; 
        otherProduct.type == currectProduct.type &amp;&amp; otherProduct.id == currectProduct.id) 
  
        // otherProduct.id == currectProduct.id becacuse i have 3 identical items of each item. //
        
        return recommandedProducts;
    };
  
  }</code></pre>
  </div>
  </div>
  </p>