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,14 @@
<form>
<div class="form-group">
<label for="Title">Titel</label>
<input type="text" class="form-control" id="Title" required [(ngModel)]="title">
</div>
<div class="form-group">
<label for="Inhalt">Inhalt</label>
<input type="text" class="form-control" id="Content" required [(ngModel)]="content">
</div>
<button type="submit" class="btn btn-success">Submit</button>
</form>

View File

@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TaskFormComponent } from './task-form.component';
describe('TaskFormComponent', () => {
let component: TaskFormComponent;
let fixture: ComponentFixture<TaskFormComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ TaskFormComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TaskFormComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

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;
}
}