angular - 我在表中尝试 ngmodel 数据但没有工作
问题描述
我需要一些帮助来解决我的问题。所以我的问题是我不能将 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)
});
}
这是代码伙计们,对不起,我发布了图片
解决方案
推荐阅读
- angular - 角度材料 mat-align-tabs 属性未正确对齐
- android - 从 API 获取并显示在屏幕上的图像/图片在截屏和通过社交媒体分享时不会被捕获
- php - 使用 python 的请求库从 PHP 页面获取 JSON 对象
- sqlite - 将表 X 中 3 列的日期添加到表 Y 中的一列
- django - Django 持续时间字段转换为 MM:SS:CC 格式?
- javascript - 在谷歌图表中如何动态显示数据点?
- javabeans - 如何一个接一个地跑豆子
- java - 在地图上使用自定义类有什么好处?
- c# - 如何在 ActionLink 无法运行的 Home Controller 中运行 LogOut Action?
- css - 堆叠在小型设备上的 Flexbox