angular - Angular 6中的内联可编辑对象列表
问题描述
我有一个清单Person
class Person {
name: string;
birthdate: Date;
}
我成功地显示了这个列表,如下所示:
<table>
<thead>
<tr>
<th>Name</th>
<th>Birthdate</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let person of persons">
<td>{{ person.name }}</td>
<td>{{ person.birthdate }}</td>
</tr>
</tbody>
</table>
现在我想使该字段name
可内联birthdate
编辑,并使用 datepicker 弹出窗口使该字段可编辑。
我还需要验证,修改将触发 web api 调用。
实现该目标的最佳方法是什么?
解决方案
您可以像这样在 td 中添加文本输入或日期选择器
在 html 文件中
<table>
<thead>
<tr>
<th>Name</th>
<th>Birthdate</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let person of persons">
<td><input type="text" (input)="onValueChange(person.name)" [(ngModel)]="person.name"/></td>
<td><input type="date" [(ngModel)]="person.birthdate"/></td>
</tr>
</tbody>
</table>
ts
onValueChange(value:any){
//this api call or whatever you need to do on value change
}
推荐阅读
- reactjs - 发送一个 TextInput 点击按钮而不导航
- python - 从 nd 数组中的 bin 索引中查找封闭网格点的索引
- javascript - 如何按标题对嵌套数组的元素进行分组?
- common-lisp - 在 REPL 中打印 BST?
- php - 无法从表模型中获取名称并使用 laravel 将其显示在视图中
- javascript - JavaScript 性能:大数组的循环和 indexOf
- ruby - Ruby CSV 比较两个 CSV 文件
- java - SwipeRefresh 布局进度条即使在完成后也不会隐藏
- azure-functions - 如何根据条件禁用 azure-time-trigger-function
- terminal - Mac OS 终端查找特定关键字图像并复制