I am currently working on filtering an array based on another array of different objects but with the same key field. Although I have made some progress, I keep encountering errors that I am unable to resolve.
@Component({
selector: 'equipment',
templateUrl: './equipment.component.html',
styleUrls: ['./equipment.component.css']
})
export class EquipmentComponent implements OnInit {
@Input() equip: OrderMachine
@Input() price: ProductPricing
inEdit = false
pricing: ProductPricing[]
accessories: ProductMachineAccessories[]
accessoriesToAdd: ProductMachineAccessories[]
constructor(private orderService: OrderService) { }
ngOnInit() {
this.pricing = this.orderService.getPricing()
this.orderService.getAccessories(this.equip.machineId).then((accessories) => {
this.accessories = accessories
this.accessoriesToAdd = accessories
console.log(this.accessoriesToAdd.length) // No error -- displays a number in the console
this.equip.accessories.forEach(function(aa) {
console.log(this.accessoriesToAdd.length) //error at the bottom
// this.accessoriesToAdd = this.accessoriesToAdd.filter(a => a.accessoryId !== aa.accessoryId)
})
})
Despite successfully displaying values in my console window, I encounter errors when attempting the same operation within the forEach loop. This issue is giving me trouble as I try to filter the arrays based on specific conditions.