Add task delete + form for add and update
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
<ul>
|
||||
<li *ngFor="let task of tasks">
|
||||
<span>Titel: {{task.titel}}</span>
|
||||
<span>Titel: {{task.title}}</span>
|
||||
<br/>
|
||||
<span>Inhalt: {{task.inhalt}}</span>
|
||||
<span>Inhalt: {{task.content}}</span>
|
||||
<button (click)="deleteTask(task)">Löschen</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -11,10 +11,29 @@ export class TaskListComponent implements OnInit {
|
||||
public tasks: Task[] = [];
|
||||
|
||||
constructor(private backendService: BackendService) {
|
||||
backendService.getTasks().subscribe(t => this.tasks.push(...t));
|
||||
backendService.getTasks().subscribe(response => {
|
||||
if (response.status > 399) {
|
||||
alert('Fehler');
|
||||
}
|
||||
else {
|
||||
this.tasks.push(...response.body);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
public deleteTask(task: Task) {
|
||||
this.backendService.deleteTask(task).subscribe(response => {
|
||||
if (response.status > 399) {
|
||||
alert('Fehler');
|
||||
}
|
||||
});
|
||||
const index = this.tasks.indexOf(task);
|
||||
if (index !== -1) {
|
||||
this.tasks.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user