删除角度2中带有http请求的数据表中的选中行

734

我有一张表,其中包含从服务器中提取的数据。我想通过选中或选中复选框并单击删除按钮来删除该行来删除行。下面是代码;

AJT82

您的组件:

@Component({
  selector: 'client',
  templateUrl:'client_table.html',
  providers:[HttpService]
  })

export class ClientComponent {

   constructor(private httpService: HttpService, private router: Router){ }
   activeClient: Client; // used as the current chosen client


  deleteClient(){
      this.httpService.deleteCustomer(this.activeClient.id)
        .subscribe(....)
  }

  checkbox(client){
    this.activeClient = client; 
    client.selected = (client.selected) ? false : true;
  }

至少从外观上看,您的模板和服务看起来不错。现在应该可以使用了!

关于您的组件的一些评论...由于您是这样导入的Clientsimport {Clients} from './Client';向您的组件中,我认为以下内容在您的组件中是不必要的。

  Clients: {
      id: number,
     first_name:string,
     last_name: string,
     email: string,
     company_name: string,
     mobile: string,
     city: string,
     website:string
  }[];

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章