Sob*_*ght 0 forms typescript angular formarray
我想从所有表单数组的实例中获取 'onduty' 值。我在 html 中试过这个:
<span *ngFor="let day of workDayandTime.controls;let i= index;">
{{day.onduty}}
</span>
Run Code Online (Sandbox Code Playgroud)
但我无法获得任何价值。
这是 json 中 workDayandTime 的值: workDayandTime 表单数组
形式 :
<span *ngFor="let day of workDayandTime.controls;let i= index;">
{{day.onduty}}
</span>
Run Code Online (Sandbox Code Playgroud)
短时paper.ts
class employerShortForm extends FormGroup {
constructor(fb: FormBuilder) {
super({
employer: fb.group({
name: new FormControl('',Validators.required),
}),
employee: fb.group({
name: new FormControl('', Validators.required)
}),
contractStart: new FormControl(''),
contractEnd: new FormControl(''),
workAddress: new FormControl('', Validators.required),
work: new FormControl('', Validators.required),
workDayandTime: fb.array([]),
wageType: new FormControl(''),
wage: new FormControl(''),
bonus: new FormControl(''),
otherWage: fb.array([]),
otherwageRadio: new FormControl(''),
overTimeAddRate: new FormControl(''),
payDateType: new FormControl(''),
payDate: new FormControl(''),
payMethod: new FormControl(''),
insurance1: new FormControl(''),
insurance2: new FormControl(''),
insurance3: new FormControl(''),
insurance4: new FormControl(''),
company: fb.group({
name: new FormControl('', Validators.required),
phone: new FormControl('', Validators.required),
address: new FormControl('', Validators.required),
}),
ownerName: new FormControl('', Validators.required),
employeeEmail: new FormControl('', Validators.required),
});
}
}Run Code Online (Sandbox Code Playgroud)
短时间paper.html
import { employerShortForm, employeeContForm, DataHandling, otherWage, workDayandTime} from '../../../contract-form'
import { FormGroup, FormControl, FormBuilder, FormArray } from '@angular/forms';
import { Component, AfterViewInit, ElementRef, Renderer2, ViewChild } from '@angular/core';
import { IonicPage, ViewController, ModalController, NavParams, Alert, NavController, Checkbox, Platform } from 'ionic-angular';
@Component({
selector: 'app-short-time-paper',
templateUrl: 'short-time-paper.html',
})
export class ShortTimePaperComponent implements AfterViewInit{
public employerForm: employerShortForm = new employerShortForm(this.fb);
ngAfterViewInit() {
this.addworkDayandTime();
}
get workDayandTime(): FormArray{
return this.employerForm.get('workDayandTime') as FormArray;
}
public addworkDayandTime() {
for (let i = 0; i < 7; i++) {
this.workDayandTime.push(this.fb.group(new workDayandTime()));
}
}
}Run Code Online (Sandbox Code Playgroud)
我删除了其他代码,但关于 formarray,我想知道的是如何在数组中获取每个实例的“onduty”值。对不起,我没有 Eng。但是如果你帮助解决这个问题。这对我来说会是很大的乐趣。谢谢。
我解决了这个,
在 HTML 中:
<span *ngFor="let day of workDayandTime.controls;let i= index;">
{{ day.controls.onduty.value }}
</span>
Run Code Online (Sandbox Code Playgroud)
这是表单数组的结构: 结构
好复杂:<
| 归档时间: |
|
| 查看次数: |
15262 次 |
| 最近记录: |