51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { CdkScrollableModule } from '@angular/cdk/scrolling';
|
|
import { Component, OnInit, inject } from '@angular/core';
|
|
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
|
|
import { MatButtonModule } from '@angular/material/button';
|
|
import { MAT_DIALOG_DATA, MatDialogRef, MatDialogModule } from '@angular/material/dialog';
|
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
|
import { MatInputModule } from '@angular/material/input';
|
|
|
|
import { MathService } from '../../shared/math.service';
|
|
|
|
@Component({
|
|
selector: 'app-quantity',
|
|
templateUrl: './quantity.component.html',
|
|
styleUrls: ['./quantity.component.css'],
|
|
imports: [
|
|
CdkScrollableModule,
|
|
MatButtonModule,
|
|
MatDialogModule,
|
|
MatFormFieldModule,
|
|
MatInputModule,
|
|
ReactiveFormsModule,
|
|
],
|
|
})
|
|
export class QuantityComponent implements OnInit {
|
|
dialogRef = inject<MatDialogRef<QuantityComponent>>(MatDialogRef);
|
|
data = inject(MAT_DIALOG_DATA);
|
|
private math = inject(MathService);
|
|
|
|
form: FormGroup<{
|
|
quantity: FormControl<string>;
|
|
}>;
|
|
|
|
constructor() {
|
|
// Create form
|
|
this.form = new FormGroup({
|
|
quantity: new FormControl<string>('', { nonNullable: true }),
|
|
});
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.form.setValue({
|
|
quantity: `${this.data}`,
|
|
});
|
|
}
|
|
|
|
accept(): void {
|
|
const quantity = this.math.parseAmount(this.form.value.quantity ?? '');
|
|
this.dialogRef.close(quantity);
|
|
}
|
|
}
|