Recently delving into Angular 6, I've encountered an issue with two components: app.component.ts and products.component.ts, as well as a service file.
In the products component, I am receiving a JSON response in the ngOnChanges method. My goal is to retrieve the length of the JSON array and pass it to the app component.
For example, if the JSON array has a length of 10, I want to display "There are 10 products in this JSON array response," or something similar.
Although everything seems to be working fine for me, I keep getting a console error that I mentioned in my title. Despite trying different solutions, I haven't been able to resolve this issue.
Here's a snippet from app.component.ts:
this.CartdataService.productCount.subscribe(
(data :any) =>{
this.size = data;
});
And here's a segment from the service file:
public productCountUnderCGS = new BehaviorSubject<number>(0);
productCount = this.prooductCountUnderCGS.asObservable();
Lastly, in products.component.ts:
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) => {
this.size = data.length;
this.CartdataService.prooductCountUnderCGS.next(this.size);
this.products = data;
});
}
If anyone could offer assistance in resolving this issue, I would greatly appreciate it.