angularjs - 每当添加新行时,如何在 ng2-smart-table 中使用 post 方法?

标签 angularjs angular post ng2-smart-table

我在 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/

相关文章:

c# - WebAPI 不尊重授权属性的 Jwt token

html - 从 MongoDB 获取带有好友 ID 的好友姓名数组

android - 使用 POST 每周向服务器发送数据

angularjs - 从 ionicView.beforeLeave 获取下一个状态

javascript - 如何设置多个 Angular UI-router 解析语句?

json - 如何删除json服务器中的所有内容

html - 无法让 fa-icon 与图像垂直对齐

C++ Qt - 只有在最后一个回复完成后才发送 POST 请求

json - 如何使用 postman 创建新用户并在keycloak中分配组?

angularjs - 编写 Jasmine 测试(BDD)时 "it"内有多个 "describe"