Add task delete + form for add and update
This commit is contained in:
39
src/app/task-form/task-form.component.ts
Normal file
39
src/app/task-form/task-form.component.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user