refactor: minor changes

This commit is contained in:
Polianin Nikita 2024-02-17 07:50:46 +03:00
parent d12abf0bee
commit 272c76cfa8

View File

@ -1,13 +1,7 @@
import {Component, EventEmitter, Input, OnInit, Output} from "@angular/core"; import {Component, EventEmitter, Input, OnInit, Output} from "@angular/core";
import {MatFormField, MatInput} from "@angular/material/input"; import {MatFormField, MatInput} from "@angular/material/input";
import {FormControl, FormsModule, ReactiveFormsModule} from "@angular/forms"; import {FormControl, ReactiveFormsModule} from "@angular/forms";
import { import {MatAutocompleteModule, MatAutocompleteSelectedEvent} from "@angular/material/autocomplete";
MatAutocomplete,
MatAutocompleteSelectedEvent,
MatAutocompleteTrigger,
MatOptgroup,
MatOption
} from "@angular/material/autocomplete";
import {AsyncPipe} from "@angular/common"; import {AsyncPipe} from "@angular/common";
import {DataSpinnerComponent} from "@component/data-spinner/data-spinner.component"; import {DataSpinnerComponent} from "@component/data-spinner/data-spinner.component";
import {map, Observable, startWith} from "rxjs"; import {map, Observable, startWith} from "rxjs";
@ -22,16 +16,12 @@ export interface Professors {
selector: 'app-schedule-tabs-professor', selector: 'app-schedule-tabs-professor',
standalone: true, standalone: true,
imports: [ imports: [
MatAutocompleteModule,
MatFormField, MatFormField,
MatInput, DataSpinnerComponent,
FormsModule,
MatAutocompleteTrigger,
MatAutocomplete,
MatOptgroup,
ReactiveFormsModule,
MatOption,
AsyncPipe, AsyncPipe,
DataSpinnerComponent ReactiveFormsModule,
MatInput
], ],
templateUrl: './schedule-tabs-professor.component.html', templateUrl: './schedule-tabs-professor.component.html',
styleUrl: './schedule-tabs-professor.component.css' styleUrl: './schedule-tabs-professor.component.css'
@ -41,7 +31,7 @@ export class ScheduleTabsProfessorComponent implements OnInit {
protected filteredTeachers!: Observable<Professors[]>; protected filteredTeachers!: Observable<Professors[]>;
@Input() teachers: Professors[] = []; @Input() teachers: Professors[] = [];
@Output() optionSelected = new EventEmitter<number>(); @Output() professorSelected = new EventEmitter<number>();
ngOnInit(): void { ngOnInit(): void {
this.filteredTeachers = this.teacherControl.valueChanges.pipe( this.filteredTeachers = this.teacherControl.valueChanges.pipe(
@ -65,7 +55,7 @@ export class ScheduleTabsProfessorComponent implements OnInit {
const selectedOption = this.teachers.find(teacher => teacher.id === event.option.value); const selectedOption = this.teachers.find(teacher => teacher.id === event.option.value);
if (selectedOption) { if (selectedOption) {
this.teacherControl.setValue(selectedOption.name); this.teacherControl.setValue(selectedOption.name);
this.optionSelected.emit(selectedOption.id); this.professorSelected.emit(selectedOption.id);
} }
} }
} }