Search code examples
angularangular-cdkangular-cdk-drag-drop

Dragable forms and save the data to json file


i want to make this https://stackblitz.com/edit/angular-dynamic-survey-creation-golkhg be dragable and save to json file, so i can make a view for the data, i've use angular cdk but i'm stuck in this function

onDrop(event: CdkDragDrop<string[]>) {
    moveItemInArray(this.items, event.previousIndex, event.currentIndex);
  }

i can't find a variable to replace this.items , can someone help me? and of course i want to store the data to json file


Solution

  • To do so, you have to upgrade your cdk version to 7.3.7 as this functionality was released in that version.

    After that in your question this.items needs to be replaced by

    this.surveyForm.get('surveyQuestions')['controls']
    

    Then this function will look like as below:

    onDrop(event: CdkDragDrop<string[]>) {
        moveItemInArray(this.surveyForm.get('surveyQuestions')['controls'], event.previousIndex, event.currentIndex);
    }