38 lines
932 B
TypeScript
38 lines
932 B
TypeScript
import { Component, Inject, OnInit } from '@angular/core';
|
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
|
|
|
import { MathService } from '../../shared/math.service';
|
|
|
|
@Component({
|
|
selector: 'app-quantity',
|
|
templateUrl: './quantity.component.html',
|
|
styleUrls: ['./quantity.component.css'],
|
|
})
|
|
export class QuantityComponent implements OnInit {
|
|
form: FormGroup;
|
|
|
|
constructor(
|
|
public dialogRef: MatDialogRef<QuantityComponent>,
|
|
@Inject(MAT_DIALOG_DATA) public data: number,
|
|
private fb: FormBuilder,
|
|
private math: MathService,
|
|
) {
|
|
// Create form
|
|
this.form = this.fb.group({
|
|
quantity: '',
|
|
});
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.form.setValue({
|
|
quantity: this.data,
|
|
});
|
|
}
|
|
|
|
accept(): void {
|
|
const quantity = this.math.parseAmount(this.form.value.quantity);
|
|
this.dialogRef.close(quantity);
|
|
}
|
|
}
|