@Input() modal: boolean
@Input() isBtn :boolean
@Output() isBtnHide = new EventEmitter()
@Output() array = new EventEmitter()
@Input() index : number
arrCars: Array<ICars> = []
formCars =
this.formBolider.group({
lastName: new FormControl('' ,Validators.required),
name: new FormControl('' ,Validators.required),
patronymic : new FormControl('',Validators.required),
number: new FormControl(''),
brand:new FormControl(''),
modal : new FormControl(''),
year: new FormControl('')
})
constructor(
private userServices : UsersService,
private formBolider :FormBuilder,
) { }
ngOnInit(): void {
this.getCars()
}
ngOnChanges():void {
this.edit()
}
edit():void {
const cars = this.arrCars.find(el =>
el.id === this.index+1)
this.formCars.patchValue({...cars})
}
getCars():void {
this.userServices.getUsers().subscribe(res=> {
this.arrCars = res
this.array.emit(this.arrCars)
})
}
modalHide( ):void {
this.isBtnHide.emit()
}
addUser():void{
const {lastName,name,patronymic,number,brand,modal,year} = this.formCars.value
const cars: ICars = new Cars(1,lastName,name,patronymic,number,brand,modal,year);
if (this.arrCars.length > 0) {
cars.id = this.arrCars.slice(-1)[0].id + 1;
}
this.userServices.addUSers(cars).subscribe(res=>{
this.getCars()
})
this.formCars.reset()
}