After running the search()
function, I want the toggle()
function to execute. However, the this.toggle(element)
function is not being performed after this.search()
.
addElement(element) {
element.isExpanded = !element.isExpanded;
const dialogRef = this.dialog.open(DialogBoxComponent, {
width: '300px',
data: element
});
dialogRef.afterClosed().subscribe(async result => {
if (result==true) {
await this.search();
this.toggle(element);
}
});
}
public search() {
this.productService.findByLabel(this.label)
.subscribe(
res=> {
this. dataSourceProduct.data = res as Product[];
},
(error) => {
this.errorService.handleError(error);
})
}
toggle(element) {
let elements = this.dataSourceProduct.data.filter(x => x.id === element.id);
elements.forEach((element: any) => {
element.isExpanded = true;
});
}