Add task delete + form for add and update
This commit is contained in:
0
src/app/task-form/task-form.component.css
Normal file
0
src/app/task-form/task-form.component.css
Normal file
14
src/app/task-form/task-form.component.html
Normal file
14
src/app/task-form/task-form.component.html
Normal 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>
|
||||
25
src/app/task-form/task-form.component.spec.ts
Normal file
25
src/app/task-form/task-form.component.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
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