add sync topping & recipelist

This commit is contained in:
pakintada@gmail.com 2024-01-19 20:23:36 +07:00
parent 45851422f7
commit d1330e4f84
3 changed files with 8 additions and 11 deletions

View file

@ -284,8 +284,6 @@ export class RecipeListComponent implements OnInit {
emitted_res.push(recipeDetailMat); emitted_res.push(recipeDetailMat);
}); });
// do another emit
this.recipeListFormChange.emit([this.toppingList, emitted_res] as unknown[]); this.recipeListFormChange.emit([this.toppingList, emitted_res] as unknown[]);
} else { } else {
this.recipeListFormChange.emit([]); this.recipeListFormChange.emit([]);
@ -561,8 +559,9 @@ export class RecipeListComponent implements OnInit {
}; };
onToppingSetChange = (event: any, index: number) => { onToppingSetChange = (event: any, index: number) => {
// console.log('onToppingSetChange at index', index, "get event", event); // where index is the actual index of slot opened for topping
this.toppingList[event[0]] = event[1]; this.toppingList[event[0]] = event[1];
// console.log('onToppingSetChange', this.toppingList); // trigger emitter
this.recipeListFormChange.emit([this.toppingList, this.recipeListData.value]);
} }
} }

View file

@ -2,7 +2,7 @@
<div formArrayName="toppingList" *ngFor="let topping of toppingList.controls; let i = index"> <div formArrayName="toppingList" *ngFor="let topping of toppingList.controls; let i = index">
<div formGroupName="{{ i }}"> <div formGroupName="{{ i }}">
<input type="checkbox" /> <input type="checkbox" formControlName="isUse"/>
<!-- toppingGroup --> <!-- toppingGroup -->
<ng-select <ng-select
appendTo="body" appendTo="body"

View file

@ -117,11 +117,10 @@ export class RecipeToppingComponent implements OnInit {
}); });
}); });
// emit value changes // emit value changes
this.toppingForm.valueChanges.subscribe((value) => { this.toppingForm.valueChanges.subscribe((value) => {
console.log('emit value', value); console.log('emit value', value, 'for index: ', this.index! - 1);
this.toppingSetChange.emit([this.index, this.toppingList.value]); this.toppingSetChange.emit([this.index! - 1, this.toppingList.value]);
}); });
} }
@ -149,13 +148,12 @@ export class RecipeToppingComponent implements OnInit {
getDefaultOfGroup(groupID: any) { getDefaultOfGroup(groupID: any) {
this.toppingList.controls.forEach((control) => { this.toppingList.controls.forEach((control) => {
if ((control.value as any).groupID == groupID) { if ((control.value as any).groupID == groupID) {
let newDefault = (this.allToppingsDefinitions as any).find( let newDefault = (this.allToppingsDefinitions as any).find(
(x: any) => x.groupId == groupID (x: any) => x.groupId == groupID
)!.default; )!.default;
control.get('defaultIDSelect')?.setValue(newDefault); control.get('defaultIDSelect')?.setValue(newDefault);
} }
}) });
} }
} }