Strict done!!
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
|
||||
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { round } from 'mathjs';
|
||||
@ -18,7 +18,7 @@ import { MathService } from '../shared/math.service';
|
||||
export class PurchaseDialogComponent implements OnInit {
|
||||
products: Observable<Product[]>;
|
||||
form: FormGroup;
|
||||
product: Product;
|
||||
product: Product = new Product();
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<PurchaseDialogComponent>,
|
||||
@ -34,7 +34,14 @@ export class PurchaseDialogComponent implements OnInit {
|
||||
tax: '',
|
||||
discount: '',
|
||||
});
|
||||
this.listenToProductAutocompleteChange();
|
||||
// Listen to Product Autocomplete Change
|
||||
this.products = (this.form.get('product') as FormControl).valueChanges.pipe(
|
||||
startWith(null),
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.productSer.autocomplete(x))),
|
||||
);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
@ -48,24 +55,13 @@ export class PurchaseDialogComponent implements OnInit {
|
||||
this.product = this.data.inventory.product;
|
||||
}
|
||||
|
||||
listenToProductAutocompleteChange(): void {
|
||||
const control = this.form.get('product');
|
||||
this.products = control.valueChanges.pipe(
|
||||
startWith(null),
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.productSer.autocomplete(x))),
|
||||
);
|
||||
}
|
||||
|
||||
displayFn(product?: Product): string | undefined {
|
||||
return product ? product.name : undefined;
|
||||
displayFn(product?: Product): string {
|
||||
return product ? product.name : '';
|
||||
}
|
||||
|
||||
productSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
this.product = event.option.value;
|
||||
this.form.get('price').setValue(this.product.price);
|
||||
(this.form.get('price') as FormControl).setValue(this.product.price);
|
||||
}
|
||||
|
||||
accept(): void {
|
||||
|
||||
Reference in New Issue
Block a user