Skip to content

Commit

Permalink
Lab #13
Browse files Browse the repository at this point in the history
  • Loading branch information
christianliebel committed Apr 25, 2024
1 parent 6d71f03 commit 97ec93d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 5 additions & 1 deletion todo/src/app/todo-create/todo-create.component.html
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
<p>todo-create works!</p>
<form [formGroup]="formGroup" (ngSubmit)="onSubmit()">
<input type="text" formControlName="name">
<input type="checkbox" formControlName="done">
<button [disabled]="formGroup.invalid">Submit!</button>
</form>
24 changes: 22 additions & 2 deletions todo/src/app/todo-create/todo-create.component.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
import { Component } from '@angular/core';
import { Component, inject } from '@angular/core';
import { NonNullableFormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
import { TodoService } from '../todo.service';
import { debounceTime } from 'rxjs';

@Component({
selector: 'app-todo-create',
standalone: true,
imports: [],
imports: [ReactiveFormsModule],
templateUrl: './todo-create.component.html',
styleUrl: './todo-create.component.scss'
})
export class TodoCreateComponent {
private readonly fb = inject(NonNullableFormBuilder);
private readonly todoService = inject(TodoService);
protected readonly formGroup = this.fb.group({
name: ['test', [Validators.required, Validators.minLength(3)]],
done: [false],
});

constructor() {
this.formGroup.valueChanges
.pipe(debounceTime(300))
.subscribe(value => console.log(value));
}

onSubmit() {
this.todoService
.create(this.formGroup.getRawValue())
.subscribe();
}
}

0 comments on commit 97ec93d

Please sign in to comment.