第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在 Angular 10 中修補(bǔ)動(dòng)態(tài)表單數(shù)組的值?

如何在 Angular 10 中修補(bǔ)動(dòng)態(tài)表單數(shù)組的值?

慕工程0101907 2023-07-20 14:58:42
我有一個(gè)動(dòng)態(tài) formArray,保存數(shù)據(jù),一切工作正常,但我在修補(bǔ)值時(shí)遇到問題,而且我在網(wǎng)上找不到任何確切的解決方案。下面是代碼,    <form [formGroup]="educationAndExperienceForm">        <div formArrayName="educationForm">            <div *ngFor="let education of educationAndExperienceForm.controls.educationForm['controls'];let i = index;"                [formGroupName]="i">                <h6 class="text-left circularBold" *ngIf="i == 0"><b>Highest Qualification</b></h6>                <input type="text" class="education-inputs w-100 mt-3" placeholder="School/College/University"                    formControlName="school"                    [ngClass]="{ 'input-error': submitted && educationAndExperienceForm.controls.educationForm.controls[i].invalid }">                <input type="text" class="education-inputs w-100 mt-3" placeholder="Degree Ex: Master's"                    formControlName="degree"                    [ngClass]="{ 'input-error': submitted && educationAndExperienceForm.controls.educationForm.controls[i].invalid }">                <input type="text" class="education-inputs w-100 mt-3"                    placeholder="Field of Education Ex: Computer Science" formControlName="specialization"                    [ngClass]="{ 'input-error': submitted && educationAndExperienceForm.controls.educationForm.controls[i].invalid }">                <div class="text-left">                    <input type="text" class="education-inputs w-100 mt-3" placeholder="Graduate Year"                        formControlName="passed_year"                        [ngClass]="{ 'input-error': submitted && educationAndExperienceForm.controls.educationForm.controls[i].invalid }">                </div>對(duì)于我使用的第一種方式,我收到無法使用 forEach.. 錯(cuò)誤
查看完整描述

1 回答

?
楊__羊羊

TA貢獻(xiàn)1943條經(jīng)驗(yàn) 獲得超7個(gè)贊

問題似乎 patchValue 無法填充表單數(shù)組。您可以使用push()像常規(guī)數(shù)組一樣填充表單數(shù)組。


假設(shè)您的 this.qualificationData 是一個(gè)包含許多“expertsQualification”(數(shù)組類型)的數(shù)組,并且類/接口 ExpertsQualification 具有屬性“school”、“l(fā)evel”、“specialization”和“passed_year”,您可以執(zhí)行以下操作:


(this.educationAndExperienceForm.controls.educationForm as FormArray).reset(); //reset the FormArray


this.qualificationData.forEach(x => {

    (this.educationAndExperienceForm.controls.educationForm as FormArray)

    .push(this.fb.group({

        school: [x.school, Validators.required],

        degree: [x.degree, Validators.required],

        specialization: [x.specialization, Validators.required],

        passed_year: [x.passed_year, Validators.required]

    });

};

..這樣您就可以循環(huán)遍歷數(shù)組,并為每個(gè)元素將表單組推送到表單數(shù)組。請(qǐng)注意,將其轉(zhuǎn)換為 FormArray 非常重要,例如


(this.educationAndExperienceForm.controls.educationForm as FormArray)

如果你不這樣做,它將保留為 AbstractControl,并且你將無法使用數(shù)組函數(shù),如推、拉等。


查看完整回答
反對(duì) 回復(fù) 2023-07-20
  • 1 回答
  • 0 關(guān)注
  • 169 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)