27 lines
774 B
TypeScript
27 lines
774 B
TypeScript
import { Component } from '@angular/core';
|
|
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
|
|
import { Student } from '../Student';
|
|
|
|
@Component({
|
|
selector: 'app-student-form-reactive',
|
|
imports: [ReactiveFormsModule],
|
|
templateUrl: './student-form-reactive.html',
|
|
styleUrl: './student-form-reactive.css',
|
|
})
|
|
export class StudentFormReactive {
|
|
form: FormGroup = null!;
|
|
|
|
ngOnInit() {
|
|
this.form = new FormGroup({
|
|
name: new FormControl<string|null>(null),
|
|
matrikelnummer: new FormControl<number|null>(null, [Validators.required, Validators.pattern('\\d+')])
|
|
});
|
|
}
|
|
|
|
print() {
|
|
const value = this.form.value;
|
|
const model = new Student(value.name, value.matrikelnummer);
|
|
console.log(model);
|
|
}
|
|
}
|