30 lines
1008 B
TypeScript
30 lines
1008 B
TypeScript
import { Component } from '@angular/core';
|
|
import {NzFormModule} from "ng-zorro-antd/form";
|
|
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms";
|
|
import {NzFlexDirective} from "ng-zorro-antd/flex";
|
|
|
|
@Component({
|
|
selector: 'app-create-book',
|
|
imports: [NzFormModule, ReactiveFormsModule, NzFlexDirective],
|
|
templateUrl: './create-book.html',
|
|
styleUrl: './create-book.css',
|
|
})
|
|
export class CreateBook {
|
|
createBookForm = new FormGroup({
|
|
title: new FormControl<string>(null, [Validators.required]),
|
|
releaseYear: new FormControl<string>(null, [Validators.required]),
|
|
author: new FormControl<string>(null, [Validators.required])
|
|
})
|
|
|
|
submitForm() {
|
|
// Pour annuler si le formulaire est invalide
|
|
if (this.createBookForm.invalid) return;
|
|
|
|
// Pour obtenir la valeur du formulaire
|
|
console.log(this.createBookForm.getRawValue())
|
|
|
|
// Pour vider le formulaire
|
|
this.createBookForm.reset()
|
|
}
|
|
}
|