41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { Component } from '@angular/core';
|
|
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} from "@angular/forms";
|
|
import {NzColDirective} from "ng-zorro-antd/grid";
|
|
import {NzFlexDirective} from "ng-zorro-antd/flex";
|
|
import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
|
|
import {NzInputDirective} from "ng-zorro-antd/input";
|
|
|
|
@Component({
|
|
selector: 'app-product-form',
|
|
imports: [
|
|
FormsModule,
|
|
NzColDirective,
|
|
NzFlexDirective,
|
|
NzFormControlComponent,
|
|
NzFormDirective,
|
|
NzFormItemComponent,
|
|
NzFormLabelComponent,
|
|
NzInputDirective,
|
|
ReactiveFormsModule
|
|
],
|
|
templateUrl: './product-form.html',
|
|
styleUrl: './product-form.css',
|
|
})
|
|
export class ProductForm {
|
|
productForm: FormGroup = new FormGroup({
|
|
price: new FormControl<string>(null, [Validators.required]),
|
|
quantity: new FormControl<string>(null, [Validators.required])
|
|
})
|
|
|
|
submitForm() {
|
|
// Pour annuler si le formulaire est invalide
|
|
if (this.productForm.invalid) return;
|
|
|
|
// Pour obtenir la valeur du formulaire
|
|
console.log(this.productForm.getRawValue())
|
|
|
|
// Pour vider le formulaire
|
|
this.productForm.reset()
|
|
}
|
|
}
|