在我的數據庫中,我有很多用戶,他們有很多食譜。每個食譜都有一些屬性和成分集合。因此,當用戶在頁面上顯示要編輯的配方時,應該會出現(表格)加載了當前數據的配方。這是一種工作,因為我可以看到數據,但我認為它做得不好。我的表格在沒有數組(成分)的情況下工作正常。你能告訴我應該如何將成分添加到我的編輯表單中嗎?如果您看到我的代碼并給我反饋并提示我應該更改什么,我將不勝感激。export class RecipeEditComponent implements OnInit {? @ViewChild('editForm') editForm: NgForm;? recipe: IRecipe;? photos: IPhoto[] = [];? ingredients: IIngredient[] = [];? uploader: FileUploader;? hasBaseDropZoneOver = false;? baseUrl = environment.apiUrl;??? currentMain: IPhoto;? constructor(private route: ActivatedRoute, private recipeService: RecipeService,? ? private toastr: ToastrService) { }? ngOnInit(): void {? ? this.loadRecipe();??? }? loadRecipe() {? ? this.recipeService.getRecipe(this.route.snapshot.params.id).subscribe(recipe => {? ? ? this.recipe = recipe;? ? ? this.initializeUploader();? ? })? }? updateRecipe(id: number) {? ? this.recipeService.editRecipe(id, this.recipe).subscribe(next => {? ? ? this.toastr.success('Recipe updated successfully');? ? ? this.editForm.reset(this.recipe);? ? }, error => {? ? ? this.toastr.error(error);? ? });? }}
在 Angular 中制作 editForm 最簡單的方法是什么?
慕碼人8056858
2023-06-09 17:52:00