Below is my code : I am trying to send arrayControl to java spring but while debugging no object is coming in data form.
saveFormFields(){
const currentUser = localStorage.getItem('currentUser');
this.DataForm.userSessionDataForm = JSON.parse(currentUser);
this.arrayControl = this.DataFormGroup.get('itemRows') as FormArray;
this.DataForm.DocumentDataForm=this.arrayControl.value;
this.Service.save(this.DataForm).subscribe(resp => {
this.DataForm = resp as DataForm;
}, error => {
console.log(error);
this.snotifyService.error(error);
})
}
这是我试图获取ArrayList的Java代码
`@RequestMapping(value = "/saveUpdate/{userToken}", method = RequestMethod.POST)
public @ResponseBody void saveUpdate(@RequestBody DataForm dataForm,
@PathVariable("userToken") String userToken, HttpServletResponse response)
throws ProcessFailed, IOException {
try {
if (!userTokenUtil.isTokenExpired(userToken)) {
DataForm saveUpdate = searchService.saveAndUpdate(dataForm);
SecurityUtils.sendResponse(response,HttpServletResponse.SC_OK, saveUpdate );
}else {
SecurityUtils.sendError(response, new BadCredentialsException("Invalid password."),
HttpServletResponse.SC_UNAUTHORIZED, "Authentication failed");
}
} catch (Exception e) {
logger.error("Error: " + e.getMessage());
SecurityUtils.sendError(response, new ProcessFailed(e.getMessage()),
HttpServletResponse.SC_SERVICE_UNAVAILABLE, e.getMessage());
}
}`
下面是我的代码:
<mat-step [stepControl]="DataFormGroup.get('Reference')">
<form [formGroup]="DataFormGroup" class="doing-form" #Reference="ngForm">
<div>
<mat-card class="col-sm-10 mx-auto">
<mat-card-header>
<mat-card-title>7. Review the reference with short description</mat-card-title>
</mat-card-header>
<mat-card-content>
<div class="doing-instructions">
<p class="learning-example">Instruction:</p>
<ul>
<li>Compare the working </li>
</ul>
</div>
<div class="doing-example">
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>Example</mat-panel-title>
</mat-expansion-panel-header>
<ul>
<li></li>
<li></li>
</ul>
<div class="text-right">
<span(click)="allExpandState=false;expandLess(4)">
<mat-icon class="expansion">expand_less</mat-icon>
</span>
</div>
</mat-expansion-panel>
</div>
<br>
<h6>Do you have document?</h6>
<mat-radio-group formControlName="Reference" [(ngModel)]="checkTable">
<mat-radio-button color="primary" value="true">Yes</mat-radio-button>
<mat-radio-button color="primary" value="false">No</mat-radio-button>
</mat-radio-group>
<mat-error *ngIf="DataFormGroup.get('Reference').errors?.required && Reference.submitted">Please select atleast one option</mat-error>
<br>
<div style="overflow-x:auto;" *ngIf="checkTable == 'true' ">
<p>List the documents in the below table</p>
<table class="table table-bordered table-responsive" id="document">
<thead>
<tr>
<th>Country Name</th>
<th>Document </th>
<th>Reference</th>
<th>Name</th>
<th>Title </th>
<th>Action</th>
</tr>
</thead>
<div formArrayName="itemRows">
<tbody>
<tr *ngFor="let itemrow of DataFormGroup.controls.itemRows.controls.slice(0,15); let i=index" [formGroupName]="i">
<td>
<input class="form-control" formControlName="countryName" >
</td>
<td>
<mat-radio-group formControlName="document">
<mat-radio-button color="primary" value="xyz">Hello</mat-radio-button>
<mat-radio-button color="primary" value="abc">Bye</mat-radio-button>
</mat-radio-group>
</td>
<td>
<input class="form-control" formControlName="reference" >
</td>
<td>
<input class="form-control" formControlName="Name" >
</td>
<td>
<input class="form-control" formControlName="title" >
</td>
<td>
<input class="form-control" formControlName="Difference">
</td>
<td>
<button mat-raised-button *ngIf="DataFormGroup.controls.itemRows.controls.length > 1" (click)="deleteRow(i)"
color="basic">
<mat-icon>delete</mat-icon>
</button>
<button mat-raised-button (click)="addNewRow()" color="primary">
<mat-icon >add</mat-icon>
</button>
</td>
</tr>
</tbody>
</div>
</table>
</div>
<!-- <button mat-raised-button (click)="autoSaveFunctionCall()">Submit</button> -->
</mat-card-content>
</mat-card>
</div>
<div class="row">
<div class="col">
<button mat-raised-button matStepperPrevious class="back">BACK</button>
</div>
<button mat-flat-button matStepperNext color="primary" class="next" (click)="saveFormFields()">NEXT</button>
</div>
</form>
</mat-step>
dataForm应该获得DocumentDataForm的值作为ArrayList,但它显示的是element:Object [0],size [0]。
实际上,我想将表保存在数据库中,通过单击“添加”按钮从用户那里获得多行。