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);
});
// do another emit
this.recipeListFormChange.emit([this.toppingList, emitted_res] as unknown[]);
} else {
this.recipeListFormChange.emit([]);
@ -561,8 +559,9 @@ export class RecipeListComponent implements OnInit {
};
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];
// 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 formGroupName="{{ i }}">
<input type="checkbox" />
<input type="checkbox" formControlName="isUse"/>
<!-- toppingGroup -->
<ng-select
appendTo="body"

View file

@ -77,7 +77,7 @@ export class RecipeToppingComponent implements OnInit {
// console.log('ToppingSet', data);
// check length of toppingList if in range with given index
if(this.index && data.length >= this.index!){
if (this.index && data.length >= this.index!) {
this.toppingList.push(
this._formBuilder.group({
isUse: data[this.index!].isUse,
@ -117,11 +117,10 @@ export class RecipeToppingComponent implements OnInit {
});
});
// emit value changes
this.toppingForm.valueChanges.subscribe((value) => {
console.log('emit value', value);
this.toppingSetChange.emit([this.index, this.toppingList.value]);
console.log('emit value', value, 'for index: ', this.index! - 1);
this.toppingSetChange.emit([this.index! - 1, this.toppingList.value]);
});
}
@ -149,13 +148,12 @@ export class RecipeToppingComponent implements OnInit {
getDefaultOfGroup(groupID: any) {
this.toppingList.controls.forEach((control) => {
if ((control.value as any).groupID == groupID) {
let newDefault = (this.allToppingsDefinitions as any).find(
(x: any) => x.groupId == groupID
)!.default;
control.get('defaultIDSelect')?.setValue(newDefault);
}
})
});
}
}