我在angular 2项目中使用了ng2 smart table
,我需要在向表中添加新行时使用API
方法发送http.post()
请求。如何获取新添加的行中每个单元格的值?
答案 0 :(得分:2)
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