1 | import { Component, OnInit } from '@angular/core';
|
---|
2 | import { MatDialogRef } from '@angular/material/dialog';
|
---|
3 | import { IMedicine } from '../../shared';
|
---|
4 | import { FormGroup, Validators, FormBuilder } from '@angular/forms';
|
---|
5 |
|
---|
6 | @Component({
|
---|
7 | selector: 'app-add-medicine-dialog',
|
---|
8 | templateUrl: './add-medicine-dialog.component.html',
|
---|
9 | styleUrls: ['./add-medicine-dialog.component.css']
|
---|
10 | })
|
---|
11 | export class AddMedicineDialogComponent implements OnInit {
|
---|
12 | medicine: IMedicine;
|
---|
13 | forma: FormGroup;
|
---|
14 |
|
---|
15 | constructor(private dialogRef: MatDialogRef<AddMedicineDialogComponent>, private formBuilder: FormBuilder) {
|
---|
16 |
|
---|
17 | }
|
---|
18 |
|
---|
19 | ngOnInit(): void {
|
---|
20 | this.forma = this.formBuilder.group({
|
---|
21 | name: ['', [Validators.required]],
|
---|
22 | strength: ['', [Validators.required]],
|
---|
23 | form: ['', [Validators.required]],
|
---|
24 | wayOfIssuing: ['', [Validators.required]],
|
---|
25 | manufacturer: ['', [Validators.required]],
|
---|
26 | price: ['', [Validators.required, Validators.min(0)]],
|
---|
27 | packaging: ['', [Validators.required]]
|
---|
28 | });
|
---|
29 | }
|
---|
30 |
|
---|
31 | save() {
|
---|
32 | this.medicine = this.forma.value;
|
---|
33 | console.log(this.forma.value);
|
---|
34 | console.log(this.medicine);
|
---|
35 | this.forma.reset();
|
---|
36 | this.dialogRef.close(this.medicine);
|
---|
37 | }
|
---|
38 |
|
---|
39 | close() {
|
---|
40 | this.dialogRef.close();
|
---|
41 | }
|
---|
42 | }
|
---|