试图使用Formarray更新论坛内部的列表

问题描述 投票:0回答:1

我正在尝试更新包含正常输入的播放列表形式和包含歌曲列表的arrayform形式。当我尝试更改两个输入时,它起作用,但是当我尝试更改数组中的任何内容时,播放列表中的所有歌曲都会被删除

更新数组列表之前:

enter image description here

按下编辑键后,我会得到:

enter image description here

并且当我尝试更改ArrayList中的任何内容时,都会得到这个

enter image description here

并且当我尝试再次编辑它时,我得到了enter image description here和一个错误:

错误TypeError:无法读取未定义的属性'map'

我将在下面保留我使用的所有功能:这在我的主要组成部分:editPlaylist(播放列表:播放列表,索引:编号){const dialogRef = this.dialog.open(DialogComponent,{宽度:“ 900px”,数据:{歌曲:this.songs,

        operation: 'edit',
        playlistData: playlist,
        position: index
      }
    });

    dialogRef.afterClosed().subscribe(result => {
      if (result) {
         this.playlists[index] = playlist;
        this.songs= result.song;
        this.playlists[index].name = result.name;
        this.playlists[index].description = result.description;



        this.playlists[index].songs = result.song;

      }
    });
  }

并且在我的对话框组件中ngOnInit():void {

   this.form = new FormGroup(
      {
        name:new FormControl('', Validators.required),
        description:new FormControl('',Validators.required),
        title:new FormControl('',Validators.required),
        artist:new FormControl('',Validators.required),
        duration:new FormControl(0,[Validators.required , Validators.min(0)]),
        songs:  this.formBuilder.array([ this.createSong() ])


      }
    )
    if (this.data.operation === 'edit') {
      this.form = this.formBuilder.group({
        name: [this.data.playlistData.name, Validators.required],
        description: [this.data.playlistData.description, Validators.required],
        songs: this.formBuilder.array(
          this.data.playlistData.songs.map(song => this.formBuilder.group({
            title: [song.title, Validators.required],
            artist: [song.artist, Validators.required],
            duration: [song.duration, Validators.compose([Validators.required, Validators.min(0)])],
          }))
        ),
      })

    }
      }

[如果有人熟悉arrayform,请帮助我

angular dialog insert-update formarray
1个回答
0
投票

我的失误是写results.songs我写了result.song.在我的playlist.componenet.ts中这是代码https://stackblitz.com/edit/angular-ivy-tfhygw

© www.soinside.com 2019 - 2024. All rights reserved.