我在 Angular 2 项目中使用了 ng2 智能表
,当我需要使用 http.post()
方法发送 API
请求时一个新行被添加到表中。如何获取新添加的行中每个单元格的值?
最佳答案
HTML
<ng2-smart-table
[settings]="settings"
[source]="data"
(createConfirm)="onPostCall($event)"
(editConfirm)="onPostCall($event)">
</ng2-smart-table>
For calling post method on both editing and creating new row
设置[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
关于angularjs - 每当添加新行时,如何在 ng2-smart-table 中使用 post 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46137522/