Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular material 我想通过选择多个值作为对象将数据发送到后端,如表2中所述_Angular Material_Angular9_Formarray_Angular2 Formbuilder_Angular Material 8 - Fatal编程技术网

Angular material 我想通过选择多个值作为对象将数据发送到后端,如表2中所述

Angular material 我想通过选择多个值作为对象将数据发送到后端,如表2中所述,angular-material,angular9,formarray,angular2-formbuilder,angular-material-8,Angular Material,Angular9,Formarray,Angular2 Formbuilder,Angular Material 8,我想实现格式2的输出,我只得到格式1。所以请帮帮我。我该怎么做?请帮帮我,我是新来的。如果我犯了愚蠢的错误,请不要对我苛刻。非常感谢。 非常感谢。 我想实现格式2的输出,我只得到格式1。所以请帮帮我。我该怎么做?请帮帮我,我是新来的。如果我犯了愚蠢的错误,请不要对我苛刻。非常感谢。 多谢各位 format:1(present output) "subjectList": [ { "subject": [ { "subjectId": 1, "subject": "English" } ] }

我想实现格式2的输出,我只得到格式1。所以请帮帮我。我该怎么做?请帮帮我,我是新来的。如果我犯了愚蠢的错误,请不要对我苛刻。非常感谢。 非常感谢。 我想实现格式2的输出,我只得到格式1。所以请帮帮我。我该怎么做?请帮帮我,我是新来的。如果我犯了愚蠢的错误,请不要对我苛刻。非常感谢。 多谢各位

format:1(present output)

"subjectList": [
{
"subject": [
{
"subjectId": 1,
"subject": "English"
}
]
}
]

format:2(desired output)   
{

"subjectList": [
{

"subjectId": 1,
"subject": "English"
},
{

"subjectId": 1,
"subject": "English"
}    
]
}
这是我的ts文件

buildteacherForm() {             

this.teacherForm = this.fb.group({
teacherId: [this.teacher.teacherId],
name: [this.teacher.name, [Validators.required, 
Validators.minLength(2), Validators.maxLength(20)]],
qualification: [this.teacher.qualification, [Validators.required, 
Validators.minLength(2), Validators.maxLength(20)]],
address: [this.teacher.address, [Validators.required, 
Validators.minLength(2), Validators.maxLength(20)]],
phoneNo: [this.teacher.phoneNo, [Validators.required, 
Validators.minLength(10)]],
dob: [this.teacher.dob, [Validators.required]],
subjectList: this.fb.array([]),

});

this.addSubjects();
}

addSubjects() {
const subjects = this.teacherForm.controls.subjectList as FormArray;
subjects.push(this.fb.group({
subject: [this.teacherSubject.subject],

}));
}

HTML: here is my html part

<div class="col-md-4">
<div
*ngFor="let teacherSubject of 
teacherForm.get('subjectList').controls;index as i"            
formArrayName="subjectList">
<div [formGroupName]="i">
<kurumba-form-group>
<mat-form-field class="example-full-width">
<mat-label>Subject list</mat-label>
<mat-select
multiple
matInput
id="subject"
formControlName="subject"
required>
<mat-option disabled> Select subject</mat-option>
<mat-option
[value]="subject"
*ngFor="let subject of teacherSubjectList"
>{{ subject.subject }}</mat-option>
</mat-select>
<mat-hint align="start">Select subject</mat-hint>
</mat-form-field>
</kurumba-form-group>
</div>
</div>
</div>
buildteacherForm(){
this.teacherForm=this.fb.group({
教师ID:[这个。教师。教师ID],
name:[this.teacher.name,[Validators.required,
Validators.minLength(2),Validators.maxLength(20)],
资格:[this.teacher.qualification,[validator.required,],
Validators.minLength(2),Validators.maxLength(20)],
地址:[this.teacher.address,[Validators.required,],
Validators.minLength(2),Validators.maxLength(20)],
phoneNo:[this.teacher.phoneNo,[Validators.required,
验证程序。最小长度(10)],
dob:[this.teacher.dob,[Validators.required]],
subjectList:this.fb.array([]),
});
这是addSubjects();
}
添加主题(){
const subjects=this.teacherForm.controls.subjectList作为FormArray;
受试者。推送(this.fb.group({
主题:[this.teacherSubject.subject],
}));
}
HTML:这是我的HTML部分
主题列表
选择主题
{{subject.subject}}
选择主题