【发布时间】:2016-09-16 15:30:18
【问题描述】:
我有一个 angular2 应用程序,它的后端是 java。我有一份客户名单。当我单击删除客户时,客户被删除但列表没有更新。如果我手动刷新页面,则列表会更新。我尝试在删除方法的订阅中路由到列表组件,但不起作用。
list-customers.component.html
<tr [class.warning]="customer.isDefault == 1" *ngFor="let customer of customers | orderBy:['firstName'] | search:searchCustomer.value;let serial = index">
<td>{{ serial+1 }}</td>
<td>{{ customer?.firstName+' '+customer?.lastName}}</td>
<td>{{ customer.email}}</td>
<td>{{ customer.mobileNumber}}</td>
<td>{{ customer.streetAddress}}</td>
<td>{{ customer.priceList?.name}}</td>
<td><a [routerLink]="['/loggedIn','customer','edit', customer.id ]"><i class="fa fa-edit fa-2x"></i></a></td>
<td><a (click)="delete(customer)"><i class="fa fa-trash-o fa-2x"></i></a></td>
</tr>
list-customers.component.ts
ngOnInit()
{
this.refreshCustomersList();
}
delete(customer)
{
this.userService.delete(customer.id)
.subscribe(
success=>
{
var index = this.customers.indexOf(customer, 0);
if (index > -1)
{
this.customers.splice(index, 1);
}
}
)
}
refreshCustomersList()
{
this._authHttp.get(
this.appService.getApiUrl() + "api/customer/list"
)
.map(res=>res.json())
.subscribe(
successResponse=>
{
this.customers = successResponse.data.customers;
},
() => console.log("Request Completed")
)
}
}
【问题讨论】:
标签: angular typescript angular2-routing angular2-template