我在我的 Angular 2 项目中使用过,当向表中添加新行时ng2 smart table
,我需要使用方法发送API
请求。http.post()
如何获取新添加行中每个单元格的值?
问问题
1659 次
1 回答
3
HTML
<ng2-smart-table
[settings]="settings"
[source]="data"
(createConfirm)="onPostCall($event)"
(editConfirm)="onPostCall($event)">
</ng2-smart-table>
用于在编辑和创建新行时调用 post 方法
设置 [TS]:
settings = {
add: {
confirmCreate: true,
},
edit: {
confirmSave: true,
},
columns:{
// your fields and titles here
}
}
更新时[TS]
onPostCall(event){
event.confirm.resolve(event.newData);
// console.log(event.newData); //this contains the new edited data
//your post request goes here
// example
const req = http.post('/api/items/add', body);
// 0 requests made - .subscribe() not called.
req.subscribe();
// 1 request made.
}
参考:https ://akveo.github.io/ng2-smart-table/#/examples/various
于 2017-09-11T12:26:03.747 回答