title: ERROR TypeError: Cannot read property 'length' of null in Angular 6
body: <p>I am new to angular 6 ,Here I have two components app.component.ts ,products.component.ts and service file .</p>
  
  <p>Here in products component receiving json response in the ngOnChanges method what I need to do is ,I want to get the json Array length and pass it to the app component .</p>
  
  <p>Ex: if json array lenth is 10 then I will display there are 10 products in this json array response like that .</p>
  
  <p>For me it's working fine .but I got the console error as I mentioned in my title .I have tried some solutions but nothing is fixed this issue.</p>
  
  <p>app.component.ts</p>
  
  <pre><code> this.CartdataService.productCount.subscribe(
    (data :any) =&gt;{
      this.size  = data;
    });
  </code></pre>
  
  <p>Service.</p>
  
  <pre><code>public prooductCountUnderCGS = new BehaviorSubject&lt;number&gt;(0);
    productCount = this.prooductCountUnderCGS.asObservable();
  </code></pre>
  
  <p>products.component.ts</p>
  
  <pre><code>ngOnChanges(changes: SimpleChanges) {
  
      this.C_code = this.CartdataService.category_code;
      this.G_code = this.CartdataService.group_code;
      this.SG_code = this.CartdataService.subgroup_code;
  
      this.CartdataService.get_Selected_Category_Of_Products(this.C_code,
        this.G_code, this.SG_code).subscribe(
          (data : any) =&gt; {
            this.size = data.length;
            this.CartdataService.prooductCountUnderCGS.next(this.size);
            this.products = data;
          });
  
    }
  </code></pre>
  
  <p>can anyone help me to fix this .</p>