2

У меня есть Drag and Drop

Код: codesandbox

Надо реализовать чтоб при перетаскивании с левого поля Drag and Drop в правое данные сетились в форму! Когда нажимал сабмит оны собирались! Проблема состоит в том что когда я делаю инициализацию в

drop(event: CdkDragDrop){}

то данные сетяться во все формы с последнего перетаскиваемого элемента! Тоесть если :

 drop(event: CdkDragDrop<string[]>) {
if (event.previousContainer === event.container) {
  moveItemInArray(
    event.container.data,
    event.previousIndex,
    event.currentIndex
  );
} else {
  console.log(event.item.data);
  transferArrayItem(
    event.previousContainer.data,
    event.container.data,
    event.previousIndex,
    event.currentIndex
  );
}
this.invoiceForms = new FormGroup({
  id: new FormControl(event.item.data.id, Validators.required),
  name: new FormControl(event.item.data.name, Validators.required),
  price: new FormControl(event.item.data.price, Validators.required),
  discount: new FormControl(0, Validators.required),
  description: new FormControl(event.item.data.description, Validators.required)
});
}

То все данные засетяться с посл. формы во все остальные!Полагаю что проблема состоит в том что formcontrolname у всех формах одны и теже , как мне задать уникалные formControl в компоненте и при ините формы?

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Посмотрите другие вопросы с метками или задайте свой вопрос.