Add task delete + form for add and update

This commit is contained in:
jfhr
2020-06-03 16:21:47 +02:00
parent f52485761e
commit 0bd4205d02
8 changed files with 126 additions and 25 deletions

View File

@@ -0,0 +1,39 @@
import { Component, OnInit, Input } from '@angular/core';
import { BackendService, Task } from '../services/backend.service';
@Component({
selector: 'app-task-form',
templateUrl: './task-form.component.html',
styleUrls: ['./task-form.component.css']
})
export class TaskFormComponent implements OnInit {
public title: string;
public content: string;
@Input()
public task: Task;
private submitted: boolean;
constructor(private backendService: BackendService) { }
ngOnInit(): void {
if (this.task !== null && this.task !== undefined) {
this.title = this.task.title;
this.content = this.task.content;
}
}
onSubmit() {
if (this.task !== null && this.task !== undefined) {
this.task.title = this.title;
this.task.content = this.content;
this.backendService.putTask(this.task);
}
else {
this.task = { title: this.title, content: this.content };
this.backendService.postTask(this.task);
}
this.submitted = true;
}
}