我想防止在角度6中删除列表的第一个ID。您有适合我的曲目吗? 我有一个允许我删除当前ID的功能:
在我的组件html中:
<div class="col-12">
<table class="mat-table">
<thead>
<tr class="mat-row no-border">
<th class="mat-header-cell ">{{'etat.titre'|translate}}</th>
<th class="mat-header-cell text-center">{{'common.date'|translate}}</th>
<th class="mat-header-cell text-center">{{'etat.majPar'|translate}}</th>
<th class="mat-header-cell text-center">{{'common.suppression'|translate}}</th>
</tr>
</thead>
<tbody>
<tr class="mat-row no-border" *ngFor="let element of dossier.etreAEtat">
<td class="mat-cell ">{{element.nom}}</td>
<td class="mat-cell text-center">{{element.date | date : 'dd/MM/yyyy'}}</td>
<td class="mat-cell text-center">{{element.nomUtilisateur}} {{element.prenomUtilisateur}}</td>
<td class="mat-cell mat-column-suppression">
<mat-icon class="blue-theme example-icon logo-piece-delete" svgIcon="logo-piece-delete" (click)="onClickDeleteEtat(element.id)"></mat-icon>
</td>
</tr>
</tbody>
</table>
</div>
在我的控制器中:
onClickDeleteEtat(id: number) {
// Ouverture d'une pop-up de de demande de confirmation de suppression
const confirmSuppressionDialog = this.dialog.open(DialogConfirmViewComponent, {
panelClass: EtatComponent.panelCssClass,
disableClose: true,
data: {dialogText: 'common.confirm-suppression', confirmText: 'oui', cancelText: 'non'}
});
confirmSuppressionDialog.afterClosed().subscribe(result => {
// Confirmation de la supppression
if (result === 'true') {
const params: RemoveEtatDossierParams = {
idEtreAEtat: id,
idDossier: this.dossier.id
};
this.dossierMetierService.deleteEtat(params);
this.snacbackService.add(this.translateService.instant('common.success-suppression', {}));
} else {
this.snacbackService.add(this.translateService.instant('common.abondon-suppression', {}));
}
});
}
服务:
deleteEtat(params: RemoveEtatDossierParams): Observable<DossierDto> {
this.dossiersService.removeEtatDossier(params).subscribe((result) => {
this._currentDossier.etreAEtat = this._currentDossier.etreAEtat.filter(etreAEtat => {
return etreAEtat.id !== params.idEtreAEtat;
});
}, (error) => {
});
return Observable.create(this._currentDossier);
}
BD中的id: