I would like to know how I can do when I delete a record from a table that is automatically removed from that table, since when I delete I always have to reload the page to no longer see the record deleted in the table.
My code ts:
import { Component, OnInit } from '@angular/core';
import {ArtistaserviceService} from './../../services/artistaservice.service';
@Component({
selector: 'app-artista',
templateUrl: './artista.component.html',
styles: []
})
export class ArtistaComponent implements OnInit{
artistas:any[] = [];
constructor(private artistaS:ArtistaserviceService) {
}
ngOnInit(){
this.artistaS.getArtistas()
.subscribe(data =>{
this.artistas = data;
console.log(this.artistas);
})
}
borrarArtista(id:string){
this.artistaS.borrarArtista(id)
.subscribe(
respuesta => {
if(respuesta){
console.log(respuesta);
}
else{
delete this.artistas[id];
}
}
)
}
}
My HTML:
<tr *ngFor="let art of artistas; let i = index">
<td>{{i+1}}</td>
<td>{{art.nombreartista}}</td>
<td>{{art.anonacimiento}}</td>
<td>{{art.descripcion1}}</td>
<td class="text-rigth w120">
<button [routerLink]="['/arts', art.idartista]" type="submit" class="btn btn-outline-success">
Editar
</button>
<button type="submit" (click)="borrarArtista(art.idartista)" class="btn btn-outline-danger">
Eliminar
</button>
</td>
</tr>
</tbody>