我的问题需要一些帮助。所以我的问题是我无法将ngmodel放在表中,并且无法对后端进行POST。每次我尝试保存数据时,都会调用ngmodel,但结果为空。
HTML:
<sb-layout-dashboard [title]="'Employee'" [hideBreadcrumbs]="false"
>
<sb-card
>
<div class="card-body">
<div class="btnNav">
<button class="btn btn-primary float-right " style="margin-left: 10px;" (click)="saveThis()">Save Data</button>
<button class="btn btn-primary float-right" (click)="fileInput.click()">Import Excel</button>
<input type="file" style="display:none" (change)="onFileSelected($event)" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" #fileInput>
</div>
<table style="width: 100%;" class="table table-bordered">
<tr style>
<th>No</th>
<th style="width:100px">NIK</th>
<th style="width:150px">Email</th>
<th>Employee Name</th>
<th>Corporate</th>
<th>Card No</th>
</tr>
<tr *ngFor="let row of data; let i = index " ngDefaultControl>
<td >{{i+1}}</td>
<!-- <p [(ngModel)]="form.nik">3213213213213</p> -->
<td [(ngModel)]="form.nik" ngDefaultControl>{{row[0]}}</td>
<td [(ngModel)]="form.email" ngDefaultControl>{{row[1]}}</td>
<td [(ngModel)]="form.namalengkap" ngDefaultControl>{{row[2]}}</td>
<td *ngIf="getCorporateName(row[3])!=false">{{ getCorporateName(row[3]) }}</td>
<td *ngIf="getCorporateName(row[3])==false">
<select [(ngModel)] = "data[i][3]">
<option value="">Pilih Corporate</option>
<option *ngFor="let item of dataCorporate" value="{{item.corporateid}}">{{item.corporatename}}</option>
</select>
</td>
<td [(ngModel)]="form.cardno" ngDefaultControl>{{row[4]}}</td>
</tr>
</table>
</div></sb-card
TS:
form: any = {
nik: '',
email: '',
fullname: '',
aliasname: '',
corporateid: '',
partnerid: '',
cardid: '',
};
功能TS:
saveThis() {
// console.log(this.form);
this.http
.post(serverurl.serverUrl.apinode + 'api/karyawan/addnew', { data: this.form })
.subscribe(res => {
console.log(res)
console.log(this.form)
});
}
这是代码专家,对不起,我发布图片