I'm getting an ID from event handler now I want to call my service method using this ID but I'm getting method undefined error. please correct me because I am new to Angular. ERROR TypeError: Cannot read property 'getTaxByCategory' of undefined
component.ts
categoryChanged(event: any){
//console.log(event.previousValue);
this.categoryId = event.value;
this.taxService.getTaxByCategory(this.categoryId).subscribe(result => {
console.log(result);
})
}
service method
public getTaxByCategory(categoryId: number): Observable < any > {
return this.taxes = this.apollo.watchQuery<Query["taxGet"]>(
{ query: taxGetByCategory, variables: { categoryId } }
).valueChanges.pipe(map(({ data }: { data: any }) => {
console.log("returned Data");
return data.taxGet;
}));
}
HTML
<dxi-item itemType="group">
<dxi-item [label]="{ text: ' Category ' }"
dataField="categoryId"
alignment="right"
editorType="dxSelectBox"
[editorOptions]="{
items: category,
placeholder: 'Select Category ',
displayExpr: 'categoryName',
valueExpr: 'id',
showClearButton: 'true',
onValueChanged: categoryChanged
}">
</dxi-item>