In my Angular project I want to implement deleting items but when I use this.currentClient.id
or .this.currentClient.name
i get this error:
Type error: Object is possibly 'null'
This is a fragment with updating currentClient data and deleting function:
export class ClientDetailsComponent implements OnInit {
currentClient = null;
message = '';
getClient(id: string | null): void {
this.clientService.get(id)
.subscribe(
data => {
this.currentClient = data;
console.log(data);
},
error => {
console.log(error);
});
}
deleteClient(): void {
this.clientService.delete(this.currentClient.id)
.subscribe(
response => {
console.log(response);
this.router.navigate(['/clients']);
},
error => {
console.log(error);
});
}
I can't find out why it can be null :(