Value is undefined in formArray

Discussão em 'Angular' iniciado por Sunstrike527, Novembro 7, 2024.

  1. Sunstrike527

    Sunstrike527 Guest

    I have form array and for some reason I dont see any value in my app-input component. if I define simple formGroup contorl and pass to app-input I can see value. But in formarray happnes something weird. When I log value I see all values are undefined

    form!: FormGroup<FormType>;

    get mtTypeControls(): FormGroup<mtTypesForm>[] {
    return this.form.controls.mtTypes.controls as FormGroup<mtTypesForm>[];
    }

    ngOnInit(): void {
    this.form = this.fb.nonNullable.group({
    mtTypes: this.fb.array([
    this.fb.group({
    nameEn: this.fb.control<string | null>('13'),
    nameRu: this.fb.control<string | null>('13'),
    analyzer: this.fb.control<string | null>('13'),
    }),
    ] as FormGroup<mtTypesForm>[]),
    });


    this.createForm([]);

    private createForm(data: MaintenanceType[]) {
    const mtTypesGroup = new FormGroup({
    nameEn: new FormControl('123'),
    nameRu: new FormControl('333'),
    analyzer: new FormControl('333'),
    }) as FormGroup<mtTypesForm>;
    this.mtTypeControls.push(mtTypesGroup);

    @for (group of mtTypeControls; track $index) {
    <div class="row margin-top-hg" (click)="test(mtTypeControls)">

    <app-input label="Name (ENG)" [formControl]="group.controls.nameEn"></app-input>

    <app-input label="Name (RUS)" [formControl]="group.controls.nameRu"></app-input>

    Continue reading...

Compartilhe esta Página