insert form into book
This commit is contained in:
28
src/app/components/create-book/create-book.ts
Normal file
28
src/app/components/create-book/create-book.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Component } from '@angular/core';
|
||||
import {NzFormModule} from "ng-zorro-antd/form";
|
||||
import {FormControl, FormGroup, Validators} from "@angular/forms";
|
||||
|
||||
@Component({
|
||||
selector: 'app-create-book',
|
||||
imports: [NzFormModule],
|
||||
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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user