我有一个表,其中包含从服务器获取的数据。我想通过勾选或选中复选框删除一行,然后点击删除按钮删除该行。以下是代码;
答案 0 :(得分:0)
您的组件:
@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;
}
您的模板和服务看起来很好,至少通过查看它。这应该可以了!
对您的组件的一些评论...因为您导入Clients
是这样的:
import {Clients} from './Client';
到您的组件,我认为您的组件中不需要以下内容。
Clients: {
id: number,
first_name:string,
last_name: string,
email: string,
company_name: string,
mobile: string,
city: string,
website:string
}[];