Below is the code I have written to filter data based on priorities (low, medium, high).
The variable priorityArr is used to store the filtered data obtained from "this.data".
The following code snippet is from the parent component, where "prio" is the variable receiving data from the child component.
Although I can successfully retrieve data in the console, I am facing difficulty displaying it on the screen and utilizing the "filter" operator from "rxjs" for this purpose.
priorityArr:any;
//used for checkbox filtering purpose
selectedCheckBoxFilter(prio:any){
console.log('demo --> ',prio)
console.log("prioLevel parent ",prio.priorityLevel)
console.log("priority array -->",this.priorityArr);
for(let i=0;i<this.data.length;i++){
if(this.data[i].priority==prio.priorityLevel){
if(prio.canEnable){
console.log(this.data[i]);
this.priorityArr.push(this.data[i])
}
}
}
}
prio.priorityLevel is the value, and prio.canEnable is used to determine if the checkbox is active. My data is in JSON array format.
this.priorityArr.push(this.data[i])
When trying to push data using the above line, I encounter the error:
TypeError: Cannot read properties of undefined (reading 'push')