ERROR TypeError : formArray를 사용하는 동안 정의되지 않은 '맵'속성을 읽을 수 없습니다.

Nisrine Hafi

다음과 같이 (formArray)를 사용하여 목록에 노래가있는 Mat-dialog에 재생 목록을 추가하는 것을 표시하려고합니다. 여기에 이미지 설명 입력

그러나 나는 계속 얻는다 :

오류 유형 오류 : 정의되지 않은 '맵'속성을 읽을 수 없습니다.

내 대화는 다음과 같습니다. 여기에 이미지 설명 입력

내 코드는 다음과 같습니다.

내 Dialog.component.html

<h1 mat-dialog-title>Create New Playlist
</h1>
<form [formGroup]='form'>
<div>

  <div mat-dialog-content>


      <mat-form-field class="input-width" appearance="standard">
        <mat-label>Playlist name</mat-label>
        <input  matInput placeholder="" required formControlName="name"  [(ngModel)]="data.name">
 
      </mat-form-field>
      <mat-form-field class="input-width" appearance="standard">
        <mat-label>Description</mat-label>
        <input  matInput placeholder="" required formControlName="description" [(ngModel)]="data.description" >
 
      </mat-form-field>
        <mat-dialog-actions class="action-buttons">
    <button mat-raised-button  color="warn" (click)="close()" >Cancel </button>
  <button mat-raised-button color="primary"  [disabled] = "form.invalid" (click)="onSubmit()" [mat-dialog-close]="data">Submit</button>

  </mat-dialog-actions>      
  <div formArrayName="songs" *ngIf="this.form">
    <div *ngFor = "let song of songsform().controls; let i = index">
      <div class="song-input-wrapper" [formGroupName]="i">
        <mat-form-field  appearance="standard">
          <mat-label>Song Title</mat-label>
          <input  matInput placeholder="" required formControlName="title">
   
        </mat-form-field>
        <mat-form-field  appearance="standard">
          <mat-label>Artist</mat-label>
          <input matInput placeholder="" required formControlName="artist">
   
        </mat-form-field>
        <mat-form-field appearance="standard">
          <mat-label>Duration</mat-label>
          <input matInput type="number" required  formControlName="duration">
          <span matSuffix>minutes</span>
        </mat-form-field>
          <button mat-icon-button color="primary" (click)="addSong()">
            <mat-icon>add_circle</mat-icon>
          </button>
          <button
          *ngIf="songsform().controls.length > 1"
          mat-icon-button
          color="warn"
          (click)="removeSong(i)"
        >
          <mat-icon>remove_circle</mat-icon>
        </button>
         
        
      </div>
    </div>
  </div>




</div>


  
  </div>
 
</form>

내 dialog.componenet.ts :

export class DialogComponent implements OnInit {

  description:string;
  songs: FormArray;

  constructor(public service: PlaylistService,public dialogRef: MatDialogRef<DialogComponent>, private formBuilder: FormBuilder, @Inject(MAT_DIALOG_DATA) public data: Playlist  ) 
   { 
   }
   form : FormGroup 
   
  songsform() :FormArray { 
    return this.form.get('songs') as FormArray ;
  }

  ngOnInit(): void {

       if (!this.data) {
      this.form = this.formBuilder.group({
        name: [null, Validators.required],
        description: [null, Validators.required],
        songs: this.formBuilder.array([ this.createSong() ]),
      });
    } else {
      this.form = this.formBuilder.group({
        name: [this.data.name, Validators.required],
        description: [this.data.description, Validators.required],
        songs: this.formBuilder.array(
          this.data.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)])],
          }))
        ),
      })}
    
  }
  close() {
    this.dialogRef.close();
}

createSong(): FormGroup {
  return this.formBuilder.group({
    title: [null, Validators.required],
    artist: [null, Validators.required],
    duration: [null, Validators.compose([Validators.required, Validators.min(0)])],
  });
}
addSong(): void {
  this.songs.push(this.createSong());
}
removeSong(index: number): void {
  if (this.songs.controls.length > 1) {
    this.songs.removeAt(index);
  }
}
  onSubmit(){

      this.dialogRef.close(this.form.value);

  }  
  }

마지막으로 대화 상자를 열고 재생 목록 클래스가있는 구성 요소 :

export interface Playlist {
  name: string;
  totalDuration: number;
  totalSongs: number;
  description: string;
  songs: Song[];
}

export interface Song {
  title: string;
  artist: string;
  duration: number;
}
@Component({
  selector: 'app-playlist',
  templateUrl: './playlist.component.html',
  styleUrls: ['./playlist.component.css']
})

export class PlaylistComponent implements OnInit {


  constructor(public dialog: MatDialog,public service: PlaylistService) { }

  ngOnInit(): void {
  }
  


  playlists: Playlist[] = [
    {
      name: 'Kopikustik',
      totalDuration: 5,
      totalSongs: 2,
      description: 'More than a coffee, this is all of your favorite accoustic songs.',
      songs: [
        {
          title: 'Cigarettes of ours',
          artist: 'Ardhito Pramono',
          duration: 3
        },
        {
          title: 'Walking Back Home',
          artist: 'Vira Talisa',
          duration: 2
        },
      ]
    },
    {
      name: 'Anime Hits',
      totalDuration: 13,
      totalSongs: 3,
      description: 'Listen to your favorite Anime songs, all in one playlist.',
      songs: [
        {
          title: 'Renai Circulation',
          artist: 'Kana Hanazawa',
          duration: 4
        },
        {
          title: 'Platinum Disco',
          artist: 'Tsukihi Phoenix',
          duration: 4
        },
        {
          title: 'Silhouette',
          artist: 'KANA-BOON',
          duration: 5
        },
      ]
    }
  ];
  name:String
  @Input() data: Playlist
  openDialog(): void {
    const dialogConfig = new MatDialogConfig();
    dialogConfig.autoFocus = false;
    const dialogRef = this.dialog.open(DialogComponent, {

      width: '900px',
      data: {
        name : this.name,
      /*  description:'',
        title:'',
        artist:'',
        duration:0*/
      }
    });

    dialogRef.afterClosed().subscribe(result => {
      console.log('The dialog was closed');
      if (result) {
        this.name = result.name;
        alert("name is :"+ this.name)
        }
    });
  }

  deletePlaylist(i)
  {
    this.playlists.splice(i, 1);
  }

}

왜 그가
this.data.songs.map (song => this.formBuilder.group ())에 문제가 있는지 이해할 수 없습니다.

누군가가 익숙하거나 내가 놓친 것을 볼 수 있다면 나를 도와주세요.

크리스

songs에 주입되는 데이터에서 초기화되지 않습니다 DialogComponent. 대화 데이터를 구성 할 때 빈 배열로 초기화 할 수 있습니다.

const dialogRef = this.dialog.open(DialogComponent, {
  width: '900px',
  data: {
    name: this.name,
    songs: []
  }
});

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

MongoError : TypeError : $ or를 사용하는 동안 정의되지 않은 'id'속성을 읽을 수 없습니다.

분류에서Dev

TypeError : 사용자 지정 유효성 검사기를 추가하는 동안 정의되지 않은 Angular의 'indexOf'속성을 읽을 수 없습니다.

분류에서Dev

TypeError : 반응에서 드롭 다운 선택을 만드는 동안 정의되지 않은 속성 '맵'을 읽을 수 없습니다.

분류에서Dev

TypeError : createAsyncThunk 및 createSlice (@ reduxjs / toolkit ":"^ 1.4.0)를 사용하는 동안 redux 툴킷에서 정의되지 않은 속성 'pending'을 읽을 수 없습니다.

분류에서Dev

ReactJs-TypeError : 정의되지 않은 '맵'속성을 읽을 수 없습니다.

분류에서Dev

차트를로드하는 동안 오류가 발생했습니다. Uncaught TypeError : 정의되지 않은 'toLowerCase'속성을 읽을 수 없습니다.

분류에서Dev

Angular Carousels : Uncaught TypeError : Angular JS와 함께 캐 러셀을 사용하는 동안 정의되지 않은 'offsetWidth'속성을 읽을 수 없습니다.

분류에서Dev

npm이 빌드를 실행하는 동안 정의되지 않은 'node'속성을 읽을 수 없습니다.

분류에서Dev

Angular 2 두 번째 맵을 초기화하는 동안 정의되지 않은 속성 '맵'을 읽을 수 없습니다.

분류에서Dev

구성 요소를 호출하면 정의되지 않은 속성 '맵'을 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 '맵'속성을 읽을 수 없습니다. 무엇을 수정해야합니까?

분류에서Dev

TypeError : 정의되지 않은 '사용자'속성을 읽을 수 없습니다.

분류에서Dev

TypeError : 상태를 사용할 때 정의되지 않은 '0'속성을 읽을 수 없습니다.

분류에서Dev

잡히지 않은 TypeError : jquery에서 json 배열을 반복하는 동안 정의되지 않은 'create'속성을 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 속성 '정보'를 읽을 수 없습니다.

분류에서Dev

Angular TypeError는 정의되지 않은 'then'속성을 읽을 수 없습니다.

분류에서Dev

Gatsby TypeError-정의되지 않은 속성 'id'를 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 속성 '문자'를 읽을 수 없습니다.

분류에서Dev

반응 : TypeError : 정의되지 않은 속성 'newCases'를 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 속성 '번호'를 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 속성 '첫 번째'를 읽을 수 없습니다.

분류에서Dev

UnhandledPromiseRejectionWarning : TypeError : 정의되지 않은 속성 'password'를 읽을 수 없습니다.

분류에서Dev

UnhandledPromiseRejectionWarning : TypeError : 정의되지 않은 속성 'id'를 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 속성 'hash'를 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 속성 '존재'를 읽을 수 없습니다.

분류에서Dev

React / MaterialUI-TypeError : 정의되지 않은 '맵'속성을 읽을 수 없습니다.

분류에서Dev

NgXs 동적 선택기 : TypeError : 정의되지 않은 속성 'x'를 읽을 수 없습니다.

분류에서Dev

UnhandledPromiseRejectionWarning : TypeError : Sequelize ORM을 사용하여 정의되지 않은 '생성'속성을 읽을 수 없습니다.

분류에서Dev

TypeError 가져 오기 : 양식을 게시하는 동안 정의되지 않은 '이름'속성을 읽을 수 없습니다-node.js

Related 관련 기사

  1. 1

    MongoError : TypeError : $ or를 사용하는 동안 정의되지 않은 'id'속성을 읽을 수 없습니다.

  2. 2

    TypeError : 사용자 지정 유효성 검사기를 추가하는 동안 정의되지 않은 Angular의 'indexOf'속성을 읽을 수 없습니다.

  3. 3

    TypeError : 반응에서 드롭 다운 선택을 만드는 동안 정의되지 않은 속성 '맵'을 읽을 수 없습니다.

  4. 4

    TypeError : createAsyncThunk 및 createSlice (@ reduxjs / toolkit ":"^ 1.4.0)를 사용하는 동안 redux 툴킷에서 정의되지 않은 속성 'pending'을 읽을 수 없습니다.

  5. 5

    ReactJs-TypeError : 정의되지 않은 '맵'속성을 읽을 수 없습니다.

  6. 6

    차트를로드하는 동안 오류가 발생했습니다. Uncaught TypeError : 정의되지 않은 'toLowerCase'속성을 읽을 수 없습니다.

  7. 7

    Angular Carousels : Uncaught TypeError : Angular JS와 함께 캐 러셀을 사용하는 동안 정의되지 않은 'offsetWidth'속성을 읽을 수 없습니다.

  8. 8

    npm이 빌드를 실행하는 동안 정의되지 않은 'node'속성을 읽을 수 없습니다.

  9. 9

    Angular 2 두 번째 맵을 초기화하는 동안 정의되지 않은 속성 '맵'을 읽을 수 없습니다.

  10. 10

    구성 요소를 호출하면 정의되지 않은 속성 '맵'을 읽을 수 없습니다.

  11. 11

    TypeError : 정의되지 않은 '맵'속성을 읽을 수 없습니다. 무엇을 수정해야합니까?

  12. 12

    TypeError : 정의되지 않은 '사용자'속성을 읽을 수 없습니다.

  13. 13

    TypeError : 상태를 사용할 때 정의되지 않은 '0'속성을 읽을 수 없습니다.

  14. 14

    잡히지 않은 TypeError : jquery에서 json 배열을 반복하는 동안 정의되지 않은 'create'속성을 읽을 수 없습니다.

  15. 15

    TypeError : 정의되지 않은 속성 '정보'를 읽을 수 없습니다.

  16. 16

    Angular TypeError는 정의되지 않은 'then'속성을 읽을 수 없습니다.

  17. 17

    Gatsby TypeError-정의되지 않은 속성 'id'를 읽을 수 없습니다.

  18. 18

    TypeError : 정의되지 않은 속성 '문자'를 읽을 수 없습니다.

  19. 19

    반응 : TypeError : 정의되지 않은 속성 'newCases'를 읽을 수 없습니다.

  20. 20

    TypeError : 정의되지 않은 속성 '번호'를 읽을 수 없습니다.

  21. 21

    TypeError : 정의되지 않은 속성 '첫 번째'를 읽을 수 없습니다.

  22. 22

    UnhandledPromiseRejectionWarning : TypeError : 정의되지 않은 속성 'password'를 읽을 수 없습니다.

  23. 23

    UnhandledPromiseRejectionWarning : TypeError : 정의되지 않은 속성 'id'를 읽을 수 없습니다.

  24. 24

    TypeError : 정의되지 않은 속성 'hash'를 읽을 수 없습니다.

  25. 25

    TypeError : 정의되지 않은 속성 '존재'를 읽을 수 없습니다.

  26. 26

    React / MaterialUI-TypeError : 정의되지 않은 '맵'속성을 읽을 수 없습니다.

  27. 27

    NgXs 동적 선택기 : TypeError : 정의되지 않은 속성 'x'를 읽을 수 없습니다.

  28. 28

    UnhandledPromiseRejectionWarning : TypeError : Sequelize ORM을 사용하여 정의되지 않은 '생성'속성을 읽을 수 없습니다.

  29. 29

    TypeError 가져 오기 : 양식을 게시하는 동안 정의되지 않은 '이름'속성을 읽을 수 없습니다-node.js

뜨겁다태그

보관